|
22 | 22 | _is_unorderable_exception, ensure_platform_int, is_bool,
|
23 | 23 | is_categorical_dtype, is_datetime64_dtype, is_datetimelike, is_dict_like,
|
24 | 24 | 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) |
27 | 26 | from pandas.core.dtypes.generic import (
|
28 | 27 | ABCDataFrame, ABCDatetimeArray, ABCDatetimeIndex, ABCSeries,
|
29 | 28 | ABCSparseArray, ABCSparseSeries)
|
@@ -2635,30 +2634,29 @@ def combine(self, other, func, fill_value=None):
|
2635 | 2634 | rv = other.get(idx, fill_value)
|
2636 | 2635 | with np.errstate(all='ignore'):
|
2637 | 2636 | new_values.append(func(lv, rv))
|
| 2637 | + new_dtype = type(func(lv, rv)) |
2638 | 2638 | else:
|
2639 | 2639 | # Assume that other is a scalar, so apply the function for
|
2640 | 2640 | # each element in the Series
|
2641 | 2641 | new_index = self.index
|
2642 | 2642 | with np.errstate(all='ignore'):
|
2643 | 2643 | new_values = [func(lv, other) for lv in self._values]
|
2644 | 2644 | new_name = self.name
|
| 2645 | + new_dtype = type(func(self._values[0], other)) |
2645 | 2646 |
|
2646 | 2647 | if is_categorical_dtype(self.values):
|
2647 | 2648 | pass
|
2648 |
| - elif is_bool(new_values[0]) and not is_sparse(self.values): |
2649 |
| - pass |
2650 | 2649 | elif is_extension_array_dtype(self.values):
|
2651 | 2650 | # The function can return something of any type, so check
|
2652 | 2651 | # if the type is compatible with the calling EA.
|
2653 | 2652 | try:
|
2654 |
| - new_values = self._values._from_sequence(new_values) |
| 2653 | + new_values = self._values._from_sequence(new_values, dtype=new_dtype) |
2655 | 2654 | except Exception:
|
2656 | 2655 | # https://github.com/pandas-dev/pandas/issues/22850
|
2657 | 2656 | # pandas has no control over what 3rd-party ExtensionArrays
|
2658 | 2657 | # do in _values_from_sequence. We still want ops to work
|
2659 | 2658 | # though, so we catch any regular Exception.
|
2660 | 2659 | pass
|
2661 |
| - |
2662 | 2660 | return self._constructor(new_values, index=new_index, name=new_name)
|
2663 | 2661 |
|
2664 | 2662 | def combine_first(self, other):
|
|
0 commit comments