Skip to content

CLN: remove unused try_cast kwarg from ops #23258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
29 changes: 13 additions & 16 deletions pandas/core/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------
Expand All @@ -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
-------
Expand All @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions pandas/core/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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)

Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/sparse/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down