Skip to content
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

DOC: add note for ExtensionArray authors on relation between argmax/min and _values_for_argsort #46022

Merged
merged 1 commit into from
Feb 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class ExtensionArray:
* dropna
* unique
* factorize / _values_for_factorize
* argsort / _values_for_argsort
* argsort, argmax, argmin / _values_for_argsort
* searchsorted

The remaining methods implemented on this class should be performant,
Expand Down Expand Up @@ -639,7 +639,7 @@ def _values_for_argsort(self) -> np.ndarray:
This means that the corresponding entries in the returned array don't need to
be modified to sort correctly.
"""
# Note: this is used in `ExtensionArray.argsort`.
# Note: this is used in `ExtensionArray.argsort/argmin/argmax`.
return np.array(self)

def argsort(
Expand Down Expand Up @@ -676,7 +676,8 @@ def argsort(
# Implementor note: You have two places to override the behavior of
# argsort.
# 1. _values_for_argsort : construct the values passed to np.argsort
# 2. argsort : total control over sorting.
# 2. argsort : total control over sorting. In case of overriding this,
# it is recommended to also override argmax/argmin
ascending = nv.validate_argsort_with_ascending(ascending, args, kwargs)

values = self._values_for_argsort()
Expand Down Expand Up @@ -707,6 +708,10 @@ def argmin(self, skipna: bool = True) -> int:
--------
ExtensionArray.argmax
"""
# Implementor note: You have two places to override the behavior of
# argmin.
# 1. _values_for_argsort : construct the values used in nargminmax
# 2. argmin itself : total control over sorting.
validate_bool_kwarg(skipna, "skipna")
if not skipna and self._hasna:
raise NotImplementedError
Expand All @@ -731,6 +736,10 @@ def argmax(self, skipna: bool = True) -> int:
--------
ExtensionArray.argmin
"""
# Implementor note: You have two places to override the behavior of
# argmax.
# 1. _values_for_argsort : construct the values used in nargminmax
# 2. argmax itself : total control over sorting.
validate_bool_kwarg(skipna, "skipna")
if not skipna and self._hasna:
raise NotImplementedError
Expand Down