From d923031cae39eae7176f42713f14e9f7ec112b92 Mon Sep 17 00:00:00 2001 From: Fandi Meng Date: Sat, 4 Oct 2025 01:09:36 -0500 Subject: [PATCH 1/2] BUG: Fixes regression in Series.pow with all-NA double[pyarrow] values in pandas 3.x (#62520) --- doc/source/whatsnew/v3.0.0.rst | 1 + pandas/core/arrays/arrow/array.py | 2 +- pandas/tests/extension/test_arrow.py | 9 +++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 98b91bf4a152c..97a586b698955 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -1226,6 +1226,7 @@ Other - Fixed bug in the :meth:`Series.rank` with object dtype and extremely small float values (:issue:`62036`) - Fixed bug where the :class:`DataFrame` constructor misclassified array-like objects with a ``.name`` attribute as :class:`Series` or :class:`Index` (:issue:`61443`) - Fixed regression in :meth:`DataFrame.from_records` not initializing subclasses properly (:issue:`57008`) +- Fixed regression in :meth:`Series.pow` on Series with all-NA ``float64[pyarrow]`` values; this now returns Series with :class:`NA` values (:issue:`62520`) .. ***DO NOT USE THIS SECTION*** diff --git a/pandas/core/arrays/arrow/array.py b/pandas/core/arrays/arrow/array.py index b8dd44a58e8ec..82f95687832a9 100644 --- a/pandas/core/arrays/arrow/array.py +++ b/pandas/core/arrays/arrow/array.py @@ -1051,7 +1051,7 @@ def _arith_method(self, other, op) -> Self | npt.NDArray[np.object_]: result = self._evaluate_op_method(other, op, ARROW_ARITHMETIC_FUNCS) if is_nan_na() and result.dtype.kind == "f": parr = result._pa_array - mask = pc.is_nan(parr).to_numpy() + mask = pc.is_nan(parr).fill_null(False).to_numpy() arr = pc.replace_with_mask(parr, mask, pa.scalar(None, type=parr.type)) result = type(self)(arr) return result diff --git a/pandas/tests/extension/test_arrow.py b/pandas/tests/extension/test_arrow.py index d2d65c4b983a7..c810f098f15cf 100644 --- a/pandas/tests/extension/test_arrow.py +++ b/pandas/tests/extension/test_arrow.py @@ -3691,3 +3691,12 @@ def test_setitem_float_nan_is_na(using_nan_is_na): ser[2] = np.nan assert isinstance(ser[2], float) assert np.isnan(ser[2]) + + +def test_pow_with_all_na_float(): + # GH#62520 + + s = pd.Series([None, None], dtype="float64[pyarrow]") + result = s.pow(2) + expected = pd.Series([pd.NA, pd.NA], dtype="float64[pyarrow]") + tm.assert_series_equal(result, expected) From 08bfc5b8ab6866db97bb644f9f56f4e5d33f5b15 Mon Sep 17 00:00:00 2001 From: Fandi Meng <64297073+fandimeng-fm@users.noreply.github.com> Date: Sat, 4 Oct 2025 18:59:30 -0500 Subject: [PATCH 2/2] Remove release note from v3.0.0.rst --- doc/source/whatsnew/v3.0.0.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 97a586b698955..98b91bf4a152c 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -1226,7 +1226,6 @@ Other - Fixed bug in the :meth:`Series.rank` with object dtype and extremely small float values (:issue:`62036`) - Fixed bug where the :class:`DataFrame` constructor misclassified array-like objects with a ``.name`` attribute as :class:`Series` or :class:`Index` (:issue:`61443`) - Fixed regression in :meth:`DataFrame.from_records` not initializing subclasses properly (:issue:`57008`) -- Fixed regression in :meth:`Series.pow` on Series with all-NA ``float64[pyarrow]`` values; this now returns Series with :class:`NA` values (:issue:`62520`) .. ***DO NOT USE THIS SECTION***