From b88df660c2b0d305d891fb82434d75e8bdeadeb3 Mon Sep 17 00:00:00 2001 From: Eltha Black Date: Sat, 13 Oct 2018 16:08:41 +0300 Subject: [PATCH] ENH implement fill_value for _combine_series_frame #13488 --- pandas/core/ops.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/pandas/core/ops.py b/pandas/core/ops.py index 640b2812d3e85..deb6b0b44f702 100644 --- a/pandas/core/ops.py +++ b/pandas/core/ops.py @@ -1750,20 +1750,31 @@ def _combine_series_frame(self, other, func, fill_value=None, axis=None, ------- result : DataFrame """ + + def wrap(res): + if fill_value is not None: + return res.fillna(fill_value) + else: + return res + if fill_value is not None: - raise NotImplementedError("fill_value {fill} not supported." - .format(fill=fill_value)) + if not is_scalar(fill_value): + raise NotImplementedError("fill_value is \ + only supported for scalar values.") + + self = self.fillna(fill_value) + other = other.fillna(fill_value) if axis is not None: axis = self._get_axis_number(axis) if axis == 0: - return self._combine_match_index(other, func, level=level) + return wrap(self._combine_match_index(other, func, level=level)) else: - return self._combine_match_columns(other, func, level=level, - try_cast=try_cast) + return wrap(self._combine_match_columns(other, func, level=level, + try_cast=try_cast)) else: if not len(other): - return self * np.nan + return wrap(self * np.nan) if not len(self): # Ambiguous case, use _series so works with DataFrame @@ -1771,8 +1782,8 @@ def _combine_series_frame(self, other, func, fill_value=None, axis=None, columns=self.columns) # default axis is columns - return self._combine_match_columns(other, func, level=level, - try_cast=try_cast) + return wrap(self._combine_match_columns(other, func, level=level, + try_cast=try_cast)) def _align_method_FRAME(left, right, axis):