Skip to content

Commit 481f8c1

Browse files
jbrockmendelNico Cernek
authored and
Nico Cernek
committed
CLN: remove unused args from _construct_result (pandas-dev#28589)
1 parent 1d5146e commit 481f8c1

File tree

2 files changed

+12
-23
lines changed

2 files changed

+12
-23
lines changed

pandas/core/frame.py

+4-17
Original file line numberDiff line numberDiff line change
@@ -5269,7 +5269,7 @@ def _arith_op(left, right):
52695269
with np.errstate(all="ignore"):
52705270
res_values = _arith_op(this.values, other.values)
52715271
new_data = dispatch_fill_zeros(func, this.values, other.values, res_values)
5272-
return this._construct_result(other, new_data, _arith_op)
5272+
return this._construct_result(new_data)
52735273

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

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

5293-
def _combine_const(self, other, func):
5294-
# scalar other or np.ndim(other) == 0
5295-
new_data = ops.dispatch_to_series(self, other, func)
5296-
return self._construct_result(other, new_data, func)
5297-
5298-
def _construct_result(self, other, result, func):
5293+
def _construct_result(self, result) -> "DataFrame":
52995294
"""
53005295
Wrap the result of an arithmetic, comparison, or logical operation.
53015296
53025297
Parameters
53035298
----------
5304-
other : object
53055299
result : DataFrame
5306-
func : binary operator
53075300
53085301
Returns
53095302
-------
53105303
DataFrame
5311-
5312-
Notes
5313-
-----
5314-
`func` is included for compat with SparseDataFrame signature, is not
5315-
needed here.
53165304
"""
53175305
out = self._constructor(result, index=self.index, copy=False)
53185306
# Pin columns instead of passing to constructor for compat with
53195307
# non-unique columns case
53205308
out.columns = self.columns
53215309
return out
5322-
# TODO: finalize? we do for SparseDataFrame
53235310

53245311
def combine(self, other, func, fill_value=None, overwrite=True):
53255312
"""

pandas/core/ops/__init__.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,8 @@ def f(self, other, axis=default_axis, level=None, fill_value=None):
892892
if fill_value is not None:
893893
self = self.fillna(fill_value)
894894

895-
return self._combine_const(other, op)
895+
new_data = dispatch_to_series(self, other, op)
896+
return self._construct_result(new_data)
896897

897898
f.__name__ = op_name
898899

@@ -926,15 +927,16 @@ def f(self, other, axis=default_axis, level=None):
926927
if not self._indexed_same(other):
927928
self, other = self.align(other, "outer", level=level, copy=False)
928929
new_data = dispatch_to_series(self, other, na_op, str_rep)
929-
return self._construct_result(other, new_data, na_op)
930+
return self._construct_result(new_data)
930931

931932
elif isinstance(other, ABCSeries):
932933
return _combine_series_frame(
933934
self, other, na_op, fill_value=None, axis=axis, level=level
934935
)
935936
else:
936937
# in this case we always have `np.ndim(other) == 0`
937-
return self._combine_const(other, na_op)
938+
new_data = dispatch_to_series(self, other, na_op)
939+
return self._construct_result(new_data)
938940

939941
f.__name__ = op_name
940942

@@ -957,7 +959,7 @@ def f(self, other):
957959
"Can only compare identically-labeled DataFrame objects"
958960
)
959961
new_data = dispatch_to_series(self, other, func, str_rep)
960-
return self._construct_result(other, new_data, func)
962+
return self._construct_result(new_data)
961963

962964
elif isinstance(other, ABCSeries):
963965
return _combine_series_frame(
@@ -967,8 +969,8 @@ def f(self, other):
967969

968970
# straight boolean comparisons we want to allow all columns
969971
# (regardless of dtype to pass thru) See #4537 for discussion.
970-
res = self._combine_const(other, func)
971-
return res
972+
new_data = dispatch_to_series(self, other, func)
973+
return self._construct_result(new_data)
972974

973975
f.__name__ = op_name
974976

0 commit comments

Comments
 (0)