Skip to content

CLN: remove unused args from _construct_result #28589

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 1 commit into from
Sep 24, 2019
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
21 changes: 4 additions & 17 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -5269,7 +5269,7 @@ def _arith_op(left, right):
with np.errstate(all="ignore"):
res_values = _arith_op(this.values, other.values)
new_data = dispatch_fill_zeros(func, this.values, other.values, res_values)
return this._construct_result(other, new_data, _arith_op)
return this._construct_result(new_data)

def _combine_match_index(self, other, func, level=None):
left, right = self.align(other, join="outer", axis=0, level=level, copy=False)
Expand All @@ -5282,44 +5282,31 @@ def _combine_match_index(self, other, func, level=None):
# fastpath --> operate directly on values
with np.errstate(all="ignore"):
new_data = func(left.values.T, right.values).T
return left._construct_result(other, new_data, func)
return left._construct_result(new_data)

def _combine_match_columns(self, other: Series, func, level=None):
left, right = self.align(other, join="outer", axis=1, level=level, copy=False)
# at this point we have `left.columns.equals(right.index)`
new_data = ops.dispatch_to_series(left, right, func, axis="columns")
return left._construct_result(right, new_data, func)
return left._construct_result(new_data)

def _combine_const(self, other, func):
# scalar other or np.ndim(other) == 0
new_data = ops.dispatch_to_series(self, other, func)
return self._construct_result(other, new_data, func)

def _construct_result(self, other, result, func):
def _construct_result(self, result) -> "DataFrame":
"""
Wrap the result of an arithmetic, comparison, or logical operation.

Parameters
----------
other : object
result : DataFrame
func : binary operator

Returns
-------
DataFrame

Notes
-----
`func` is included for compat with SparseDataFrame signature, is not
needed here.
"""
out = self._constructor(result, index=self.index, copy=False)
# Pin columns instead of passing to constructor for compat with
# non-unique columns case
out.columns = self.columns
return out
# TODO: finalize? we do for SparseDataFrame

def combine(self, other, func, fill_value=None, overwrite=True):
"""
Expand Down
14 changes: 8 additions & 6 deletions pandas/core/ops/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,8 @@ def f(self, other, axis=default_axis, level=None, fill_value=None):
if fill_value is not None:
self = self.fillna(fill_value)

return self._combine_const(other, op)
new_data = dispatch_to_series(self, other, op)
return self._construct_result(new_data)

f.__name__ = op_name

Expand Down Expand Up @@ -926,15 +927,16 @@ def f(self, other, axis=default_axis, level=None):
if not self._indexed_same(other):
self, other = self.align(other, "outer", level=level, copy=False)
new_data = dispatch_to_series(self, other, na_op, str_rep)
return self._construct_result(other, new_data, na_op)
return self._construct_result(new_data)

elif isinstance(other, ABCSeries):
return _combine_series_frame(
self, other, na_op, fill_value=None, axis=axis, level=level
)
else:
# in this case we always have `np.ndim(other) == 0`
return self._combine_const(other, na_op)
new_data = dispatch_to_series(self, other, na_op)
return self._construct_result(new_data)

f.__name__ = op_name

Expand All @@ -957,7 +959,7 @@ def f(self, other):
"Can only compare identically-labeled DataFrame objects"
)
new_data = dispatch_to_series(self, other, func, str_rep)
return self._construct_result(other, new_data, func)
return self._construct_result(new_data)

elif isinstance(other, ABCSeries):
return _combine_series_frame(
Expand All @@ -967,8 +969,8 @@ def f(self, other):

# 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)
return res
new_data = dispatch_to_series(self, other, func)
return self._construct_result(new_data)

f.__name__ = op_name

Expand Down