-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
REF: implement putmask for CI/DTI/TDI/PI #36400
Changes from all commits
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 |
---|---|---|
|
@@ -422,6 +422,17 @@ def where(self, cond, other=None): | |
cat = Categorical(values, dtype=self.dtype) | ||
return type(self)._simple_new(cat, name=self.name) | ||
|
||
def putmask(self, mask, value): | ||
try: | ||
code_value = self._data._validate_where_value(value) | ||
except (TypeError, ValueError): | ||
return self.astype(object).putmask(mask, value) | ||
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. this is hit in tests? |
||
|
||
codes = self._data._ndarray.copy() | ||
np.putmask(codes, mask, code_value) | ||
cat = self._data._from_backing_data(codes) | ||
return type(self)._simple_new(cat, name=self.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. this hit in tests? 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. looks like we have coverage for all of the datetimelike but none of the categorical; will update |
||
|
||
def reindex(self, target, method=None, level=None, limit=None, tolerance=None): | ||
""" | ||
Create index with target's values (move/add/delete values as necessary) | ||
|
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.
not necessarily for today. but is there any value to pushing this down to the array and having a putmask_compat until NEP18 can be supported?
putmask on the Index returns a copy whereas putmask compat on the array would be expected to be inplace. This may not be so easy for Categorical, but for other numpy backed arrays could be more trivial.
also is the goal of extension array backed indexes to allow 3rd party EAs in the Index. If so, putmask on the array would need to be added to the EA interface?
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.
I would be in favor of this
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.
yep I am also +1 on this as this is a 'standard' array method, can you create an issue (we might have one?)