Skip to content

BUG: Add min/max methods to ArrowExtensionArray GH#61311 #61924

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions pandas/core/arrays/arrow/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -2948,6 +2948,14 @@ def _dt_tz_convert(self, tz) -> Self:
result = self._pa_array.cast(pa.timestamp(current_unit, tz))
return type(self)(result)

def max(self, *, skipna: bool = True, axis: int | None = 0, **kwargs):
"""Return the maximum value of the array."""
return self._reduce("max", skipna=skipna, **kwargs)

def min(self, *, skipna: bool = True, axis: int | None = 0, **kwargs):
"""Return the minimum value of the array."""
return self._reduce("min", skipna=skipna, **kwargs)


def transpose_homogeneous_pyarrow(
arrays: Sequence[ArrowExtensionArray],
Expand Down
13 changes: 13 additions & 0 deletions pandas/tests/arrays/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,3 +530,16 @@ def test_array_to_numpy_na():
result = arr.to_numpy(na_value=True, dtype=bool)
expected = np.array([True, True])
tm.assert_numpy_array_equal(result, expected)


def test_array_max_min():
pytest.importorskip("pyarrow")
# GH#61311
df = pd.DataFrame({"a": [1, 2], "c": [0, 2], "d": ["c", "a"]})
expected = df.iloc[:, df["c"]]
df_pyarrow = pd.DataFrame(
{"a": [1, 2], "c": [0, 2], "d": ["c", "a"]}
).convert_dtypes(dtype_backend="pyarrow")
result = df_pyarrow.iloc[:, df_pyarrow["c"]]
expected_pyarrow = expected.convert_dtypes(dtype_backend="pyarrow")
tm.assert_frame_equal(result, expected_pyarrow)
Loading