Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,7 @@ ExtensionArray
- Bug in comparison between object with :class:`ArrowDtype` and incompatible-dtyped (e.g. string vs bool) incorrectly raising instead of returning all-``False`` (for ``==``) or all-``True`` (for ``!=``) (:issue:`59505`)
- Bug in constructing pandas data structures when passing into ``dtype`` a string of the type followed by ``[pyarrow]`` while PyArrow is not installed would raise ``NameError`` rather than ``ImportError`` (:issue:`57928`)
- Bug in various :class:`DataFrame` reductions for pyarrow temporal dtypes returning incorrect dtype when result was null (:issue:`59234`)
- Fixed flex arithmetic with :class:`ExtensionArray` operands raising when ``fill_value`` was passed. (:issue:`62467`)

Styler
^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -6062,7 +6062,7 @@ def _flex_method(self, other, op, *, level=None, fill_value=None, axis: Axis = 0

if isinstance(other, Series):
return self._binop(other, op, level=level, fill_value=fill_value)
elif isinstance(other, (np.ndarray, list, tuple)):
elif isinstance(other, (np.ndarray, list, tuple, ExtensionArray)):
if len(other) != len(self):
raise ValueError("Lengths must be equal")
other = self._constructor(other, self.index, copy=False)
Expand Down
38 changes: 38 additions & 0 deletions pandas/tests/series/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,28 @@ def _check_fill(meth, op, a, b, fill_value=0):
# should accept axis=0 or axis='rows'
op(a, b, axis=0)

@pytest.mark.parametrize("kind", ["datetime", "timedelta"])
def test_rhs_extension_array_sub_with_fill_value(self, kind):
# GH:62467
if kind == "datetime":
left = Series(
[pd.Timestamp("2025-08-20"), pd.Timestamp("2025-08-21")],
dtype=np.dtype("datetime64[ns]"),
)
else:
left = Series(
[Timedelta(days=1), Timedelta(days=2)],
dtype=np.dtype("timedelta64[ns]"),
)

right = (
left._values
) # DatetimeArray or TimedeltaArray which is an ExtensionArray

result = left.sub(right, fill_value=left.iloc[0])
expected = Series(np.zeros(len(left), dtype=np.dtype("timedelta64[ns]")))
tm.assert_series_equal(result, expected)

def test_flex_disallows_dataframe(self):
# GH#46179
df = pd.DataFrame(
Expand Down Expand Up @@ -430,6 +452,22 @@ def test_comparison_flex_alignment(self, values, op):
expected = Series(values, index=list("abcd"))
tm.assert_series_equal(result, expected)

@pytest.mark.parametrize(
"left",
[
Series(Categorical(["a", "b", "a"])),
Series(pd.period_range("2020Q1", periods=3, freq="Q")),
],
ids=["categorical", "period"],
)
def test_rhs_extension_array_eq_with_fill_value(self, left):
# GH:#62467
right = left._values # this is an ExtensionArray

result = left.eq(right, fill_value=left.iloc[0])
expected = Series([True, True, True])
tm.assert_series_equal(result, expected)

@pytest.mark.parametrize(
"values, op, fill_value",
[
Expand Down
Loading