From 4c62f03c2035f6037da09e6753e79be016ba36dd Mon Sep 17 00:00:00 2001 From: Rohan Jain Date: Tue, 17 Oct 2023 18:04:31 -0700 Subject: [PATCH 1/3] fix pow with missing operand --- doc/source/whatsnew/v2.1.2.rst | 1 + pandas/core/series.py | 2 ++ pandas/tests/extension/test_arrow.py | 8 ++++++++ 3 files changed, 11 insertions(+) diff --git a/doc/source/whatsnew/v2.1.2.rst b/doc/source/whatsnew/v2.1.2.rst index cc51e22265d7c..c74d9006ec200 100644 --- a/doc/source/whatsnew/v2.1.2.rst +++ b/doc/source/whatsnew/v2.1.2.rst @@ -29,6 +29,7 @@ Bug fixes - Fixed bug in :meth:`DataFrame.interpolate` raising incorrect error message (:issue:`55347`) - Fixed bug in :meth:`Index.insert` raising when inserting ``None`` into :class:`Index` with ``dtype="string[pyarrow_numpy]"`` (:issue:`55365`) - Fixed bug in :meth:`Series.all` and :meth:`Series.any` not treating missing values correctly for ``dtype="string[pyarrow_numpy]"`` (:issue:`55367`) +- Fixed bug in :meth:`Series.pow` not filling missing values correctly (:issue:`55512`) - Fixed bug in :meth:`Series.rank` for ``string[pyarrow_numpy]`` dtype (:issue:`55362`) - Silence ``Period[B]`` warnings introduced by :issue:`53446` during normal plotting activity (:issue:`55138`) - diff --git a/pandas/core/series.py b/pandas/core/series.py index c6e1e460b336a..724a54c85da9b 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -6043,6 +6043,8 @@ def _flex_method(self, other, op, *, level=None, fill_value=None, axis: Axis = 0 return result else: if fill_value is not None: + if isna(other): + return op(self, fill_value) self = self.fillna(fill_value) return op(self, other) diff --git a/pandas/tests/extension/test_arrow.py b/pandas/tests/extension/test_arrow.py index 86aef2642750e..f9fcfd19e9956 100644 --- a/pandas/tests/extension/test_arrow.py +++ b/pandas/tests/extension/test_arrow.py @@ -3017,6 +3017,14 @@ def test_arrowextensiondtype_dataframe_repr(): assert result == expected +def test_pow_missing_operand(): + # GH 55512 + k = pd.Series([2, None], dtype="int64[pyarrow]") + result = k.pow(None, fill_value=3) + expected = pd.Series([8, None], dtype="int64[pyarrow]") + tm.assert_series_equal(result, expected) + + @pytest.mark.parametrize("pa_type", tm.TIMEDELTA_PYARROW_DTYPES) def test_duration_fillna_numpy(pa_type): # GH 54707 From 59229dcee5aef2d4045ac46e90eac4a5898baf05 Mon Sep 17 00:00:00 2001 From: Rohan Jain Date: Wed, 18 Oct 2023 10:29:14 -0700 Subject: [PATCH 2/3] move to 2.2.0 --- doc/source/whatsnew/v2.1.2.rst | 1 - doc/source/whatsnew/v2.2.0.rst | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v2.1.2.rst b/doc/source/whatsnew/v2.1.2.rst index c74d9006ec200..cc51e22265d7c 100644 --- a/doc/source/whatsnew/v2.1.2.rst +++ b/doc/source/whatsnew/v2.1.2.rst @@ -29,7 +29,6 @@ Bug fixes - Fixed bug in :meth:`DataFrame.interpolate` raising incorrect error message (:issue:`55347`) - Fixed bug in :meth:`Index.insert` raising when inserting ``None`` into :class:`Index` with ``dtype="string[pyarrow_numpy]"`` (:issue:`55365`) - Fixed bug in :meth:`Series.all` and :meth:`Series.any` not treating missing values correctly for ``dtype="string[pyarrow_numpy]"`` (:issue:`55367`) -- Fixed bug in :meth:`Series.pow` not filling missing values correctly (:issue:`55512`) - Fixed bug in :meth:`Series.rank` for ``string[pyarrow_numpy]`` dtype (:issue:`55362`) - Silence ``Period[B]`` warnings introduced by :issue:`53446` during normal plotting activity (:issue:`55138`) - diff --git a/doc/source/whatsnew/v2.2.0.rst b/doc/source/whatsnew/v2.2.0.rst index b29d35c8ce332..0ce01b7f890b1 100644 --- a/doc/source/whatsnew/v2.2.0.rst +++ b/doc/source/whatsnew/v2.2.0.rst @@ -317,6 +317,7 @@ Timezones Numeric ^^^^^^^ - Bug in :func:`read_csv` with ``engine="pyarrow"`` causing rounding errors for large integers (:issue:`52505`) +- Fixed bug in :meth:`Series.pow` not filling missing values correctly (:issue:`55512`) - Conversion From cc8c4ec220a6fce07b5898ef2eedcf4511fc14b3 Mon Sep 17 00:00:00 2001 From: rohanjain101 <38412262+rohanjain101@users.noreply.github.com> Date: Wed, 18 Oct 2023 16:40:36 -0400 Subject: [PATCH 3/3] Update doc/source/whatsnew/v2.2.0.rst Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> --- doc/source/whatsnew/v2.2.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v2.2.0.rst b/doc/source/whatsnew/v2.2.0.rst index 0ce01b7f890b1..4f5f31da75e03 100644 --- a/doc/source/whatsnew/v2.2.0.rst +++ b/doc/source/whatsnew/v2.2.0.rst @@ -317,7 +317,7 @@ Timezones Numeric ^^^^^^^ - Bug in :func:`read_csv` with ``engine="pyarrow"`` causing rounding errors for large integers (:issue:`52505`) -- Fixed bug in :meth:`Series.pow` not filling missing values correctly (:issue:`55512`) +- Bug in :meth:`Series.pow` not filling missing values correctly (:issue:`55512`) - Conversion