Skip to content

Commit 96fa493

Browse files
committed
fix for infering dtype in failing s.combine on extention array
1 parent e6655bc commit 96fa493

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

pandas/core/series.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2634,21 +2634,21 @@ def combine(self, other, func, fill_value=None):
26342634
rv = other.get(idx, fill_value)
26352635
with np.errstate(all='ignore'):
26362636
new_values.append(func(lv, rv))
2637-
new_dtype = type(func(lv, rv))
26382637
else:
26392638
# Assume that other is a scalar, so apply the function for
26402639
# each element in the Series
26412640
new_index = self.index
26422641
with np.errstate(all='ignore'):
26432642
new_values = [func(lv, other) for lv in self._values]
26442643
new_name = self.name
2645-
new_dtype = type(func(self._values[0], other))
26462644

26472645
if is_categorical_dtype(self.values):
26482646
pass
26492647
elif is_extension_array_dtype(self.values):
26502648
# The function can return something of any type, so check
26512649
# if the type is compatible with the calling EA.
2650+
non_na_values = [v for v in new_values if notna(v)]
2651+
new_dtype, _ = infer_dtype_from(non_na_values, pandas_dtype=True)
26522652
try:
26532653
new_values = self._values._from_sequence(new_values, dtype=new_dtype)
26542654
except Exception:

pandas/tests/extension/base/methods.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,14 @@ def test_combine_add(self, data_repeated):
164164
orig_data1._from_sequence([a + b for (a, b) in
165165
zip(list(orig_data1),
166166
list(orig_data2))],
167-
dtype=s1.dtype))
167+
dtype=s1.dtype))
168168
self.assert_series_equal(result, expected)
169169

170170
val = s1.iloc[0]
171171
result = s1.combine(val, lambda x1, x2: x1 + x2)
172172
expected = pd.Series(
173173
orig_data1._from_sequence([a + val for a in list(orig_data1)],
174-
dtype=s1.dtype))
174+
dtype=s1.dtype))
175175
self.assert_series_equal(result, expected)
176176

177177
def test_combine_first(self, data):

0 commit comments

Comments
 (0)