Skip to content

ENH: Add support for Index.min/max with arrow string #51401

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

Merged
merged 2 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ Other enhancements
- :meth:`Series.dropna` and :meth:`DataFrame.dropna` has gained ``ignore_index`` keyword to reset index (:issue:`31725`)
- Improved error message in :func:`to_datetime` for non-ISO8601 formats, informing users about the position of the first error (:issue:`50361`)
- Improved error message when trying to align :class:`DataFrame` objects (for example, in :func:`DataFrame.compare`) to clarify that "identically labelled" refers to both index and columns (:issue:`50083`)
- Added support for :meth:`Index.min` and :meth:`Index.max` for pyarrow string dtypes (:issue:`51397`)
- Added :meth:`DatetimeIndex.as_unit` and :meth:`TimedeltaIndex.as_unit` to convert to different resolutions; supported resolutions are "s", "ms", "us", and "ns" (:issue:`50616`)
- Added :meth:`Series.dt.unit` and :meth:`Series.dt.as_unit` to convert to different resolutions; supported resolutions are "s", "ms", "us", and "ns" (:issue:`51223`)
- Added new argument ``dtype`` to :func:`read_sql` to be consistent with :func:`read_sql_query` (:issue:`50797`)
Expand Down
6 changes: 2 additions & 4 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6928,8 +6928,7 @@ def min(self, axis=None, skipna: bool = True, *args, **kwargs):
return self._na_value

if not self._is_multi and not isinstance(self._values, np.ndarray):
# "ExtensionArray" has no attribute "min"
return self._values.min(skipna=skipna) # type: ignore[attr-defined]
return self._values._reduce(name="min", skipna=skipna)

return super().min(skipna=skipna)

Expand All @@ -6954,8 +6953,7 @@ def max(self, axis=None, skipna: bool = True, *args, **kwargs):
return self._na_value

if not self._is_multi and not isinstance(self._values, np.ndarray):
# "ExtensionArray" has no attribute "max"
return self._values.max(skipna=skipna) # type: ignore[attr-defined]
return self._values._reduce(name="max", skipna=skipna)

return super().max(skipna=skipna)

Expand Down
4 changes: 0 additions & 4 deletions pandas/tests/indexes/test_numpy_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,6 @@ def test_numpy_ufuncs_reductions(index, func, request):
if len(index) == 0:
return

if repr(index.dtype) == "string[pyarrow]":
mark = pytest.mark.xfail(reason="ArrowStringArray has no min/max")
request.node.add_marker(mark)

Comment on lines -161 to -164
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

if isinstance(index, CategoricalIndex) and index.dtype.ordered is False:
with pytest.raises(TypeError, match="is not ordered for"):
func.reduce(index)
Expand Down