diff --git a/doc/source/whatsnew/v2.2.0.rst b/doc/source/whatsnew/v2.2.0.rst index b29d35c8ce332..4f5f31da75e03 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`) +- Bug in :meth:`Series.pow` not filling missing values correctly (:issue:`55512`) - Conversion 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