-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
ENH: Support mask in unique #48109
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
ENH: Support mask in unique #48109
Conversation
pandas/core/algorithms.py
Outdated
|
|
||
|
|
||
| def unique(values): | ||
| def unique(values, mask=None): |
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 sure if this is a good idea, since this changes the api. A better alternative would probably be a _unique function that can take a mask
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.
agreed
also can annotate mask?
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, will do when moving to a private function
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.
Done
|
This probably closes #30037 |
pandas/core/arrays/masked.py
Outdated
| ------- | ||
| uniques : BaseMaskedArray | ||
| """ | ||
| uniques, mask = algos._unique(self._data, self._mask) |
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.
nitpick, can you rename the function to something non-private, e.g. unique_with_mask
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.
Sure, done
jorisvandenbossche
left a comment
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 great!
| The labels from values to uniques | ||
| mask : ndarray[bool], optional | ||
| If not None, the mask is used as indicator for missing values | ||
| (True = missing, False = valid) instead of `na_value` or |
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.
Was this meant to be added to the Parameters section?
(although actually also the return value changes if passing a mask, maybe that can be clarified as well)
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 thanks. Moved the mask part up and added a result_mask return value
|
Would merge tomorrow if no objections |
|
Thanks @phofl ! |
doc/source/whatsnew/vX.X.X.rstfile if fixing a bug or adding a new feature.cc @jorisvandenbossche