Skip to content

Commit 8fdf658

Browse files
author
Mayank
committed
BUG: handle ExtensionArray in Series._flex_method with fill_value (fixes #62467)
1 parent 9469794 commit 8fdf658

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

pandas/core/series.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6062,7 +6062,7 @@ def _flex_method(self, other, op, *, level=None, fill_value=None, axis: Axis = 0
60626062

60636063
if isinstance(other, Series):
60646064
return self._binop(other, op, level=level, fill_value=fill_value)
6065-
elif isinstance(other, (np.ndarray, list, tuple)):
6065+
elif isinstance(other, (np.ndarray, list, tuple, ExtensionArray)):
60666066
if len(other) != len(self):
60676067
raise ValueError("Lengths must be equal")
60686068
other = self._constructor(other, self.index, copy=False)

pandas/tests/series/test_arithmetic.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ def _permute(obj):
4545

4646

4747
class TestSeriesFlexArithmetic:
48+
def test_flex_op_with_extensionarray_and_fill_value(self):
49+
# GH#62467 ensure ExtensionArray "other" with fill_value works
50+
left = Series([pd.Timestamp(2025, 8, 20)] * 2)
51+
right = left._values # ExtensionArray (DatetimeArray)
52+
result = left.sub(right, fill_value=left[0])
53+
expected = Series([Timedelta(0), Timedelta(0)])
54+
tm.assert_series_equal(result, expected)
4855
@pytest.mark.parametrize(
4956
"ts",
5057
[

0 commit comments

Comments
 (0)