Skip to content

Commit

Permalink
DOC: add note for ExtensionArray authors on relation between argmax/m…
Browse files Browse the repository at this point in the history
…in and _values_for_argsort (pandas-dev#46022)
  • Loading branch information
jorisvandenbossche authored Feb 16, 2022
1 parent 6cd6069 commit 6dc2b94
Showing 1 changed file with 12 additions and 3 deletions.
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

0 comments on commit 6dc2b94

Please sign in to comment.