Skip to content

Commit e6655bc

Browse files
committed
quickfix failing s.combine on extention array
1 parent cb207aa commit e6655bc

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

pandas/core/series.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
_is_unorderable_exception, ensure_platform_int, is_bool,
2323
is_categorical_dtype, is_datetime64_dtype, is_datetimelike, is_dict_like,
2424
is_extension_array_dtype, is_extension_type, is_hashable, is_integer,
25-
is_iterator, is_list_like, is_scalar, is_sparse, is_string_like,
26-
is_timedelta64_dtype)
25+
is_iterator, is_list_like, is_scalar, is_string_like, is_timedelta64_dtype)
2726
from pandas.core.dtypes.generic import (
2827
ABCDataFrame, ABCDatetimeArray, ABCDatetimeIndex, ABCSeries,
2928
ABCSparseArray, ABCSparseSeries)
@@ -2635,30 +2634,29 @@ def combine(self, other, func, fill_value=None):
26352634
rv = other.get(idx, fill_value)
26362635
with np.errstate(all='ignore'):
26372636
new_values.append(func(lv, rv))
2637+
new_dtype = type(func(lv, rv))
26382638
else:
26392639
# Assume that other is a scalar, so apply the function for
26402640
# each element in the Series
26412641
new_index = self.index
26422642
with np.errstate(all='ignore'):
26432643
new_values = [func(lv, other) for lv in self._values]
26442644
new_name = self.name
2645+
new_dtype = type(func(self._values[0], other))
26452646

26462647
if is_categorical_dtype(self.values):
26472648
pass
2648-
elif is_bool(new_values[0]) and not is_sparse(self.values):
2649-
pass
26502649
elif is_extension_array_dtype(self.values):
26512650
# The function can return something of any type, so check
26522651
# if the type is compatible with the calling EA.
26532652
try:
2654-
new_values = self._values._from_sequence(new_values)
2653+
new_values = self._values._from_sequence(new_values, dtype=new_dtype)
26552654
except Exception:
26562655
# https://github.com/pandas-dev/pandas/issues/22850
26572656
# pandas has no control over what 3rd-party ExtensionArrays
26582657
# do in _values_from_sequence. We still want ops to work
26592658
# though, so we catch any regular Exception.
26602659
pass
2661-
26622660
return self._constructor(new_values, index=new_index, name=new_name)
26632661

26642662
def combine_first(self, other):

pandas/tests/extension/base/methods.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,15 @@ def test_combine_add(self, data_repeated):
163163
expected = pd.Series(
164164
orig_data1._from_sequence([a + b for (a, b) in
165165
zip(list(orig_data1),
166-
list(orig_data2))]))
166+
list(orig_data2))],
167+
dtype=s1.dtype))
167168
self.assert_series_equal(result, expected)
168169

169170
val = s1.iloc[0]
170171
result = s1.combine(val, lambda x1, x2: x1 + x2)
171172
expected = pd.Series(
172-
orig_data1._from_sequence([a + val for a in list(orig_data1)]))
173+
orig_data1._from_sequence([a + val for a in list(orig_data1)],
174+
dtype=s1.dtype))
173175
self.assert_series_equal(result, expected)
174176

175177
def test_combine_first(self, data):

0 commit comments

Comments
 (0)