-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: make Index.where behavior mirror Index.putmask behavior #39412
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 3 commits
079706b
1e42b33
a16ab28
9a209d1
7bac106
a49e1f6
7738c95
03edf69
a3df8b9
39cf572
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -799,29 +799,22 @@ def length(self): | |
return Index(self._data.length, copy=False) | ||
|
||
def putmask(self, mask, value): | ||
arr = self._data.copy() | ||
mask = np.asarray(mask, dtype=bool) | ||
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. can't you share / use the array/interval putmask code here? 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. we do; L814-815 is directly using IntervalArray.putmask. everything before that point is for ways that the Index method behaves differently from the array method |
||
if mask.shape != self.shape: | ||
raise ValueError("putmask: mask and data must be the same size") | ||
if not mask.any(): | ||
return self.copy() | ||
|
||
try: | ||
value_left, value_right = arr._validate_setitem_value(value) | ||
self._validate_fill_value(value) | ||
except (ValueError, TypeError): | ||
return self.astype(object).putmask(mask, value) | ||
dtype = self._find_common_type_compat(value) | ||
return self.astype(dtype).putmask(mask, value) | ||
|
||
if isinstance(self._data._left, np.ndarray): | ||
np.putmask(arr._left, mask, value_left) | ||
np.putmask(arr._right, mask, value_right) | ||
else: | ||
# TODO: special case not needed with __array_function__ | ||
arr._left.putmask(mask, value_left) | ||
arr._right.putmask(mask, value_right) | ||
arr = self._data.copy() | ||
arr.putmask(mask, value) | ||
return type(self)._simple_new(arr, name=self.name) | ||
|
||
@Appender(Index.where.__doc__) | ||
def where(self, cond, other=None): | ||
if other is None: | ||
other = self._na_value | ||
values = np.where(cond, self._values, other) | ||
result = IntervalArray(values) | ||
return type(self)._simple_new(result, name=self.name) | ||
|
||
def insert(self, loc, item): | ||
""" | ||
Return a new IntervalIndex inserting new item at location. Follows | ||
|
@@ -998,6 +991,9 @@ def func(self, other, sort=sort): | |
|
||
# -------------------------------------------------------------------- | ||
|
||
def _validate_fill_value(self, value): | ||
return self._data._validate_setitem_value(value) | ||
|
||
@property | ||
def _is_all_dates(self) -> bool: | ||
""" | ||
|
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.
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.
we'll always be making a copy here since dtype != self.dtype