-
-
Notifications
You must be signed in to change notification settings - Fork 18.3k
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: Add argmax and argmin to ExtensionArray #27801
Changes from 33 commits
8303674
44838f7
8bc9573
bc69a4a
4787c63
8bd82f5
e84268b
f9c9fea
8b7585f
41e8ce4
20ca0a2
1aa7422
f2b6958
7d81cc5
d18c8bb
3530a6a
8d8506a
e7e7c86
10f9b27
ccded0b
9aea8fe
5636d2a
4db39e0
2036b25
d81a8f8
58d46d0
6b88790
8cd7169
810ac56
6b030aa
e5a6d8c
d7a49c1
65e1e4c
1b64e2f
2cdf16b
7c79f5c
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 |
---|---|---|
|
@@ -319,6 +319,33 @@ def nargsort( | |
return indexer | ||
|
||
|
||
def nargminmax(values, method: str): | ||
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. annotate values as EA? |
||
""" | ||
Implementation of np.argmin/argmax but for ExtensionArray and which | ||
handles missing values. | ||
|
||
Parameters | ||
---------- | ||
values : ExtensionArray | ||
method : {"argmax", "argmin"} | ||
|
||
Returns | ||
------- | ||
int | ||
""" | ||
assert method in {"argmax", "argmin"} | ||
func = np.argmax if method == "argmax" else np.argmin | ||
|
||
mask = np.asarray(isna(values)) | ||
TomAugspurger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
values = values._values_for_argsort() | ||
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. im not wild about relying on non-public attrs here. could we have the EA method pass 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.
I know we have had the discussion about the point of |
||
|
||
idx = np.arange(len(values)) | ||
non_nans = values[~mask] | ||
non_nan_idx = idx[~mask] | ||
|
||
return non_nan_idx[func(non_nans)] | ||
|
||
|
||
def ensure_key_mapped_multiindex(index, key: Callable, level=None): | ||
""" | ||
Returns a new MultiIndex in which key has been applied | ||
|
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 don’t think these
should be in base.py
rather in array_ops
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.
The reason I put them here is because I think it makes sense to keep it close to
nargsort
, since the code is very similar (using the same approach with theidx
/non_nan_idx
etc)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.
BTW, this is not
base.py
, butcore/sorting.py
, which groups a whole bunch of functionality related to sortable values.(it might make sense to move
sorting.py
into thearray_ops
submodule, but I would do that as a separate move)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.
k that makes sense (and let’s move sorting.py) as a followon