From 125037d30a812aba7f2093dd7f326a8401b7d336 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Sat, 20 Oct 2018 13:32:06 -0700 Subject: [PATCH] remove unused try_cast kwarg --- pandas/core/frame.py | 7 +++---- pandas/core/internals/blocks.py | 10 ++-------- pandas/core/ops.py | 31 ++++++++++++++----------------- pandas/core/panel.py | 8 ++++---- pandas/core/sparse/frame.py | 4 ++-- 5 files changed, 25 insertions(+), 35 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index fd18d4860997d..313371e4d7e07 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -4971,20 +4971,19 @@ 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'): if lib.is_scalar(other) or np.ndim(other) == 0: return ops.dispatch_to_series(self, other, func) new_data = self._data.eval(func=func, other=other, - errors=errors, - try_cast=try_cast) + errors=errors) return self._constructor(new_data) def combine(self, other, func, fill_value=None, overwrite=True): diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 6fb1184f48b69..33f0febdd5378 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -1318,7 +1318,7 @@ def shift(self, periods, axis=0, mgr=None): return [self.make_block(new_values)] - def eval(self, func, other, errors='raise', try_cast=False, mgr=None): + def eval(self, func, other, errors='raise', mgr=None): """ evaluate the block; return result block from the result @@ -1330,8 +1330,6 @@ def eval(self, func, other, errors='raise', try_cast=False, mgr=None): - ``raise`` : allow exceptions to be raised - ``ignore`` : suppress exceptions. On error return original object - try_cast : try casting the results to the input type - Returns ------- a new block, the result of the func @@ -1368,7 +1366,7 @@ def eval(self, func, other, errors='raise', try_cast=False, mgr=None): block = self.coerce_to_target_dtype(orig_other) return block.eval(func, orig_other, errors=errors, - try_cast=try_cast, mgr=mgr) + mgr=mgr) # get the result, may need to transpose the other def get_result(other): @@ -1450,10 +1448,6 @@ def handle_error(): # transpose if needed result = transf(result) - # try to cast if requested - if try_cast: - result = self._try_cast_result(result) - result = _block_shape(result, ndim=self.ndim) return [self.make_block(result)] diff --git a/pandas/core/ops.py b/pandas/core/ops.py index daa87ad173772..2cd37f31cb751 100644 --- a/pandas/core/ops.py +++ b/pandas/core/ops.py @@ -1725,10 +1725,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 ---------- @@ -1738,7 +1738,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 ------- @@ -1753,8 +1752,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 @@ -1765,8 +1763,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): @@ -1866,13 +1863,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) - pass_op = op if lib.is_scalar(other) else na_op - return self._combine_const(other, pass_op, try_cast=True) + assert np.ndim(other) == 0, other + return self._combine_const(other, op) f.__name__ = op_name @@ -1908,9 +1905,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 @@ -1933,14 +1931,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 @@ -1987,13 +1984,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,