Skip to content

Commit 03491bd

Browse files
committed
BUG: Add min/max methods to ArrowExtensionArray for iloc indexing GH#61311
1 parent 628c7fb commit 03491bd

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

pandas/core/arrays/arrow/array.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2948,6 +2948,14 @@ def _dt_tz_convert(self, tz) -> Self:
29482948
result = self._pa_array.cast(pa.timestamp(current_unit, tz))
29492949
return type(self)(result)
29502950

2951+
def max(self, *, skipna: bool = True, axis: int | None = 0, **kwargs):
2952+
"""Return the maximum value of the array."""
2953+
return self._reduce("max", skipna=skipna, **kwargs)
2954+
2955+
def min(self, *, skipna: bool = True, axis: int | None = 0, **kwargs):
2956+
"""Return the minimum value of the array."""
2957+
return self._reduce("min", skipna=skipna, **kwargs)
2958+
29512959

29522960
def transpose_homogeneous_pyarrow(
29532961
arrays: Sequence[ArrowExtensionArray],

pandas/tests/arrays/test_array.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,3 +530,15 @@ def test_array_to_numpy_na():
530530
result = arr.to_numpy(na_value=True, dtype=bool)
531531
expected = np.array([True, True])
532532
tm.assert_numpy_array_equal(result, expected)
533+
534+
535+
def test_array_max_min():
536+
# GH#61311
537+
df = pd.DataFrame({"a": [1, 2], "c": [0, 2], "d": ["c", "a"]})
538+
expected = df.iloc[:, df["c"]]
539+
df_pyarrow = pd.DataFrame(
540+
{"a": [1, 2], "c": [0, 2], "d": ["c", "a"]}
541+
).convert_dtypes(dtype_backend="pyarrow")
542+
result = df_pyarrow.iloc[:, df_pyarrow["c"]]
543+
expected_pyarrow = expected.convert_dtypes(dtype_backend="pyarrow")
544+
tm.assert_frame_equal(result, expected_pyarrow)

0 commit comments

Comments
 (0)