-
-
Notifications
You must be signed in to change notification settings - Fork 19.1k
REF: IntervalIndex[IntervalArray] #20611
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
9b8564f
9e5fc50
abb8a45
4e48e88
11d97db
de96a61
24db222
d2bb35a
f22b453
934f238
097b9a4
c2bca65
39249a3
f82df72
e0fe0bc
7c0ffd3
e89d89a
a33940a
382737d
95f8f15
e82eeb6
bccb4f7
99ab41f
385ce59
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -454,11 +454,11 @@ def __getitem__(self, value): | |||||||||||||||
|
||||||||||||||||
def __setitem__(self, key, value): | ||||||||||||||||
# na value: need special casing to set directly on numpy arrays | ||||||||||||||||
_needs_float_conversion = False | ||||||||||||||||
needs_float_conversion = False | ||||||||||||||||
if is_scalar(value) and isna(value): | ||||||||||||||||
if is_integer_dtype(self.dtype.subtype): | ||||||||||||||||
# can't set NaN on a numpy integer array | ||||||||||||||||
_needs_float_conversion = True | ||||||||||||||||
needs_float_conversion = True | ||||||||||||||||
elif is_datetime64_any_dtype(self.dtype.subtype): | ||||||||||||||||
# need proper NaT to set directly on the numpy array | ||||||||||||||||
value = np.datetime64('NaT') | ||||||||||||||||
|
@@ -485,13 +485,13 @@ def __setitem__(self, key, value): | |||||||||||||||
# Need to ensure that left and right are updated atomically, so we're | ||||||||||||||||
# forced to copy, update the copy, and swap in the new values. | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure I am clear why this is problematic. is there a failure possible when updating the 2nd one? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without the forcing the copy I'm seeing pandas/pandas/tests/extension/base/setitem.py Lines 17 to 23 in 1dd05cc
|
||||||||||||||||
left = self.left.copy(deep=True) | ||||||||||||||||
if _needs_float_conversion: | ||||||||||||||||
if needs_float_conversion: | ||||||||||||||||
left = left.astype('float') | ||||||||||||||||
left.values[key] = value_left | ||||||||||||||||
self._left = left | ||||||||||||||||
|
||||||||||||||||
right = self.right.copy(deep=True) | ||||||||||||||||
if _needs_float_conversion: | ||||||||||||||||
if needs_float_conversion: | ||||||||||||||||
right = right.astype('float') | ||||||||||||||||
right.values[key] = value_right | ||||||||||||||||
self._right = right | ||||||||||||||||
|
@@ -505,7 +505,7 @@ def fillna(self, value=None, method=None, limit=None): | |||||||||||||||
|
||||||||||||||||
if not isinstance(value, ABCInterval): | ||||||||||||||||
msg = ("'IntervalArray.fillna' only supports filling with a " | ||||||||||||||||
"'scalar pandas.Interval'. Got a '{}' instead." | ||||||||||||||||
"scalar 'pandas.Interval'. Got a '{}' instead." | ||||||||||||||||
.format(type(value).__name__)) | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Single quote is in the wrong place. Should be |
||||||||||||||||
raise TypeError(msg) | ||||||||||||||||
|
||||||||||||||||
|
@@ -580,7 +580,6 @@ def _concat_same_type(cls, to_concat): | |||||||||||||||
raise ValueError("Intervals must all be closed on the same side.") | ||||||||||||||||
closed = closed.pop() | ||||||||||||||||
|
||||||||||||||||
# TODO: avoid intermediate list | ||||||||||||||||
left = np.concatenate([interval.left for interval in to_concat]) | ||||||||||||||||
right = np.concatenate([interval.right for interval in to_concat]) | ||||||||||||||||
return cls._simple_new(left, right, closed=closed, copy=False) | ||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this support the case where
value
isnp.nan
? Doesn't look like that currently works.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it currently fails. I'll see what can be done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like there's also something strange going on with datetime data: