Skip to content

Commit 155a9d1

Browse files
committed
Clean and remove unnecessry checks
1 parent 96ddd0d commit 155a9d1

File tree

4 files changed

+8
-10
lines changed

4 files changed

+8
-10
lines changed

Diff for: pandas/core/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1482,7 +1482,7 @@ def _arith_method(self, other, op):
14821482

14831483
return self._construct_result(result, name=res_name, other=other)
14841484

1485-
def _construct_result(self, result, name, other=None):
1485+
def _construct_result(self, result, name, other):
14861486
"""
14871487
Construct an appropriately-wrapped result from the ArrayLike result
14881488
of an arithmetic-like operation.

Diff for: pandas/core/frame.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -8100,7 +8100,6 @@ def _align_for_op(
81008100
left : DataFrame
81018101
right : Any
81028102
"""
8103-
81048103
left, right = self, other
81058104

81068105
def to_series(right):
@@ -8200,6 +8199,7 @@ def to_series(right):
82008199
"`left, right = left.align(right, axis=1)` "
82018200
"before operating."
82028201
)
8202+
82038203
left, right = left.align(
82048204
right,
82058205
join="outer",
@@ -8269,7 +8269,7 @@ def _flex_arith_method(
82698269

82708270
return self._construct_result(new_data, other=other)
82718271

8272-
def _construct_result(self, result, other=None) -> DataFrame:
8272+
def _construct_result(self, result, other) -> DataFrame:
82738273
"""
82748274
Wrap the result of an arithmetic, comparison, or logical operation.
82758275
@@ -8286,8 +8286,7 @@ def _construct_result(self, result, other=None) -> DataFrame:
82868286
# non-unique columns case
82878287
out.columns = self.columns
82888288
out.index = self.index
8289-
if not getattr(self, "attrs", None) and getattr(other, "attrs", None):
8290-
out = out.__finalize__(other)
8289+
out = out.__finalize__(other)
82918290
return out
82928291

82938292
def __divmod__(self, other) -> tuple[DataFrame, DataFrame]:

Diff for: pandas/core/indexes/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7151,7 +7151,7 @@ def _logical_method(self, other, op):
71517151
return self._construct_result(res_values, name=res_name, other=other)
71527152

71537153
@final
7154-
def _construct_result(self, result, name, other=None):
7154+
def _construct_result(self, result, name, other):
71557155
if isinstance(result, tuple):
71567156
return (
71577157
Index(result[0], name=name, dtype=result[0].dtype),

Diff for: pandas/core/series.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -5938,7 +5938,7 @@ def _construct_result(
59385938
self,
59395939
result: ArrayLike | tuple[ArrayLike, ArrayLike],
59405940
name: Hashable,
5941-
other: AnyArrayLike | DataFrame | None = None,
5941+
other: AnyArrayLike | DataFrame,
59425942
) -> Series | tuple[Series, Series]:
59435943
"""
59445944
Construct an appropriately-labelled Series from the result of an op.
@@ -5947,7 +5947,7 @@ def _construct_result(
59475947
----------
59485948
result : ndarray or ExtensionArray
59495949
name : Label
5950-
other : Series, DataFrame or array-like, default None
5950+
other : Series, DataFrame or array-like
59515951
59525952
Returns
59535953
-------
@@ -5970,8 +5970,7 @@ def _construct_result(
59705970
dtype = getattr(result, "dtype", None)
59715971
out = self._constructor(result, index=self.index, dtype=dtype, copy=False)
59725972
out = out.__finalize__(self)
5973-
if getattr(other, "attrs", None):
5974-
out.__finalize__(other)
5973+
out = out.__finalize__(other)
59755974

59765975
# Set the result's name after __finalize__ is called because __finalize__
59775976
# would set it back to self.name

0 commit comments

Comments
 (0)