diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 257e8a8c6d726..6dd9174028f18 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -4971,14 +4971,14 @@ def _combine_match_index(self, other, func, level=None): index=left.index, columns=self.columns, copy=False) - def _combine_match_columns(self, other, func, level=None, try_cast=True): + def _combine_match_columns(self, other, func, level=None): assert isinstance(other, Series) left, right = self.align(other, join='outer', axis=1, level=level, copy=False) assert left.columns.equals(right.index) return ops.dispatch_to_series(left, right, func, axis="columns") - def _combine_const(self, other, func, errors='raise', try_cast=True): + def _combine_const(self, other, func, errors='raise'): assert lib.is_scalar(other) or np.ndim(other) == 0 return ops.dispatch_to_series(self, other, func) diff --git a/pandas/core/ops.py b/pandas/core/ops.py index 42d9fbd4b7585..f29b4410fbf54 100644 --- a/pandas/core/ops.py +++ b/pandas/core/ops.py @@ -1726,10 +1726,10 @@ def column_op(a, b): def _combine_series_frame(self, other, func, fill_value=None, axis=None, - level=None, try_cast=True): + level=None): """ Apply binary operator `func` to self, other using alignment and fill - conventions determined by the fill_value, axis, level, and try_cast kwargs. + conventions determined by the fill_value, axis, and level kwargs. Parameters ---------- @@ -1739,7 +1739,6 @@ def _combine_series_frame(self, other, func, fill_value=None, axis=None, fill_value : object, default None axis : {0, 1, 'columns', 'index', None}, default None level : int or None, default None - try_cast : bool, default True Returns ------- @@ -1754,8 +1753,7 @@ def _combine_series_frame(self, other, func, fill_value=None, axis=None, if axis == 0: return self._combine_match_index(other, func, level=level) else: - return self._combine_match_columns(other, func, level=level, - try_cast=try_cast) + return self._combine_match_columns(other, func, level=level) else: if not len(other): return self * np.nan @@ -1766,8 +1764,7 @@ 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 self._combine_match_columns(other, func, level=level) def _align_method_FRAME(left, right, axis): @@ -1867,13 +1864,13 @@ def f(self, other, axis=default_axis, level=None, fill_value=None): pass_op = op if axis in [0, "columns", None] else na_op return _combine_series_frame(self, other, pass_op, fill_value=fill_value, axis=axis, - level=level, try_cast=True) + level=level) else: if fill_value is not None: self = self.fillna(fill_value) assert np.ndim(other) == 0 - return self._combine_const(other, op, try_cast=True) + return self._combine_const(other, op) f.__name__ = op_name @@ -1909,9 +1906,10 @@ def f(self, other, axis=default_axis, level=None): elif isinstance(other, ABCSeries): return _combine_series_frame(self, other, na_op, fill_value=None, axis=axis, - level=level, try_cast=False) + level=level) else: - return self._combine_const(other, na_op, try_cast=False) + assert np.ndim(other) == 0, other + return self._combine_const(other, na_op) f.__name__ = op_name @@ -1937,14 +1935,13 @@ def f(self, other): elif isinstance(other, ABCSeries): return _combine_series_frame(self, other, func, fill_value=None, axis=None, - level=None, try_cast=False) + level=None) else: # straight boolean comparisons we want to allow all columns # (regardless of dtype to pass thru) See #4537 for discussion. res = self._combine_const(other, func, - errors='ignore', - try_cast=False) + errors='ignore') return res.fillna(True).astype(bool) f.__name__ = op_name @@ -1991,13 +1988,13 @@ def f(self, other, axis=None): self._get_axis_number(axis) if isinstance(other, self._constructor): - return self._compare_constructor(other, na_op, try_cast=False) + return self._compare_constructor(other, na_op) elif isinstance(other, (self._constructor_sliced, ABCDataFrame, ABCSeries)): raise Exception("input needs alignment for this object [{object}]" .format(object=self._constructor)) else: - return self._combine_const(other, na_op, try_cast=False) + return self._combine_const(other, na_op) f.__name__ = op_name diff --git a/pandas/core/panel.py b/pandas/core/panel.py index 1e2d4000413bb..72b014b018735 100644 --- a/pandas/core/panel.py +++ b/pandas/core/panel.py @@ -330,7 +330,7 @@ def _init_matrix(self, data, axes, dtype=None, copy=False): # ---------------------------------------------------------------------- # Comparison methods - def _compare_constructor(self, other, func, try_cast=True): + def _compare_constructor(self, other, func): if not self._indexed_same(other): raise Exception('Can only compare identically-labeled ' 'same type objects') @@ -745,13 +745,13 @@ def _combine(self, other, func, axis=0): "{otype!s} is not supported in combine operation with " "{selftype!s}".format(otype=type(other), selftype=type(self))) - def _combine_const(self, other, func, try_cast=True): + def _combine_const(self, other, func): with np.errstate(all='ignore'): new_values = func(self.values, other) d = self._construct_axes_dict() return self._constructor(new_values, **d) - def _combine_frame(self, other, func, axis=0, try_cast=True): + def _combine_frame(self, other, func, axis=0): index, columns = self._get_plane_axes(axis) axis = self._get_axis_number(axis) @@ -770,7 +770,7 @@ def _combine_frame(self, other, func, axis=0, try_cast=True): return self._constructor(new_values, self.items, self.major_axis, self.minor_axis) - def _combine_panel(self, other, func, try_cast=True): + def _combine_panel(self, other, func): items = self.items.union(other.items) major = self.major_axis.union(other.major_axis) minor = self.minor_axis.union(other.minor_axis) diff --git a/pandas/core/sparse/frame.py b/pandas/core/sparse/frame.py index 2ed275e3bbd2d..e46df2b2bde70 100644 --- a/pandas/core/sparse/frame.py +++ b/pandas/core/sparse/frame.py @@ -618,7 +618,7 @@ def _combine_match_index(self, other, func, level=None): new_data, index=new_index, columns=self.columns, default_fill_value=fill_value).__finalize__(self) - def _combine_match_columns(self, other, func, level=None, try_cast=True): + def _combine_match_columns(self, other, func, level=None): # patched version of DataFrame._combine_match_columns to account for # NumPy circumventing __rsub__ with float64 types, e.g.: 3.0 - series, # where 3.0 is numpy.float64 and series is a SparseSeries. Still @@ -642,7 +642,7 @@ def _combine_match_columns(self, other, func, level=None, try_cast=True): new_data, index=self.index, columns=union, default_fill_value=self.default_fill_value).__finalize__(self) - def _combine_const(self, other, func, errors='raise', try_cast=True): + def _combine_const(self, other, func, errors='raise'): return self._apply_columns(lambda x: func(x, other)) def _reindex_index(self, index, method, copy, level, fill_value=np.nan,