From 03491bd0c2c3f33f024291239c2f0e60c9bc9d48 Mon Sep 17 00:00:00 2001 From: skonda29 Date: Tue, 22 Jul 2025 13:39:30 -0700 Subject: [PATCH 1/2] BUG: Add min/max methods to ArrowExtensionArray for iloc indexing GH#61311 --- pandas/core/arrays/arrow/array.py | 8 ++++++++ pandas/tests/arrays/test_array.py | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/pandas/core/arrays/arrow/array.py b/pandas/core/arrays/arrow/array.py index 919453b29b7f9..89eb49dadbcc8 100644 --- a/pandas/core/arrays/arrow/array.py +++ b/pandas/core/arrays/arrow/array.py @@ -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], diff --git a/pandas/tests/arrays/test_array.py b/pandas/tests/arrays/test_array.py index 3c0ef1e4d928b..5ce6631feeb04 100644 --- a/pandas/tests/arrays/test_array.py +++ b/pandas/tests/arrays/test_array.py @@ -530,3 +530,15 @@ 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(): + # 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) From 126d75999375d3c59c70c2ca1cd2490c2c8d8bf3 Mon Sep 17 00:00:00 2001 From: skonda29 Date: Tue, 22 Jul 2025 15:13:18 -0700 Subject: [PATCH 2/2] Fixed CI failures --- pandas/tests/arrays/test_array.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/tests/arrays/test_array.py b/pandas/tests/arrays/test_array.py index 5ce6631feeb04..a522eeea37f27 100644 --- a/pandas/tests/arrays/test_array.py +++ b/pandas/tests/arrays/test_array.py @@ -533,6 +533,7 @@ def test_array_to_numpy_na(): 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"]]