Skip to content

Commit 2607f9c

Browse files
committed
Fix some tests in pandas/tests/generic/test_finalize.py::test_binops
1 parent bc4da65 commit 2607f9c

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

pandas/core/base.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,6 +1454,8 @@ def _duplicated(self, keep: DropKeep = "first") -> npt.NDArray[np.bool_]:
14541454
return algorithms.duplicated(arr, keep=keep)
14551455

14561456
def _arith_method(self, other, op):
1457+
if not getattr(self, "attrs", None) and getattr(other, "attrs", None):
1458+
self.attrs = other.attrs
14571459
res_name = ops.get_op_result_name(self, other)
14581460

14591461
lvalues = self._values
@@ -1466,9 +1468,6 @@ def _arith_method(self, other, op):
14661468
with np.errstate(all="ignore"):
14671469
result = ops.arithmetic_op(lvalues, rvalues, op)
14681470

1469-
if not getattr(self, "attrs", None) and getattr(other, "attrs", None):
1470-
self.attrs = other.attrs
1471-
14721471
return self._construct_result(result, name=res_name)
14731472

14741473
def _construct_result(self, result, name):

pandas/core/frame.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7813,13 +7813,19 @@ class diet
78137813
def _cmp_method(self, other, op):
78147814
axis: Literal[1] = 1 # only relevant for Series other case
78157815

7816+
if not getattr(self, "attrs", None) and getattr(other, "attrs", None):
7817+
self.attrs = other.attrs
7818+
78167819
self, other = self._align_for_op(other, axis, flex=False, level=None)
78177820

78187821
# See GH#4537 for discussion of scalar op behavior
78197822
new_data = self._dispatch_frame_op(other, op, axis=axis)
78207823
return self._construct_result(new_data)
78217824

78227825
def _arith_method(self, other, op):
7826+
if not getattr(self, "attrs", None) and getattr(other, "attrs", None):
7827+
self.attrs = other.attrs
7828+
78237829
if self._should_reindex_frame_op(other, op, 1, None, None):
78247830
return self._arith_method_with_reindex(other, op)
78257831

@@ -7830,10 +7836,6 @@ def _arith_method(self, other, op):
78307836

78317837
with np.errstate(all="ignore"):
78327838
new_data = self._dispatch_frame_op(other, op, axis=axis)
7833-
7834-
if not getattr(self, "attrs", None) and getattr(other, "attrs", None):
7835-
self.attrs = other.attrs
7836-
78377839
return self._construct_result(new_data)
78387840

78397841
_logical_method = _arith_method
@@ -8230,6 +8232,9 @@ def _flex_cmp_method(self, other, op, *, axis: Axis = "columns", level=None):
82308232

82318233
self, other = self._align_for_op(other, axis, flex=True, level=level)
82328234

8235+
if not getattr(self, "attrs", None) and getattr(other, "attrs", None):
8236+
self.attrs = other.attrs
8237+
82338238
new_data = self._dispatch_frame_op(other, op, axis=axis)
82348239
return self._construct_result(new_data)
82358240

pandas/core/series.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5836,6 +5836,9 @@ def to_period(
58365836
def _cmp_method(self, other, op):
58375837
res_name = ops.get_op_result_name(self, other)
58385838

5839+
if not getattr(self, "attrs", None) and getattr(other, "attrs", None):
5840+
self.attrs = other.attrs
5841+
58395842
if isinstance(other, Series) and not self._indexed_same(other):
58405843
raise ValueError("Can only compare identically-labeled Series objects")
58415844

@@ -5847,6 +5850,8 @@ def _cmp_method(self, other, op):
58475850
return self._construct_result(res_values, name=res_name)
58485851

58495852
def _logical_method(self, other, op):
5853+
if not getattr(self, "attrs", None) and getattr(other, "attrs", None):
5854+
self.attrs = other.attrs
58505855
res_name = ops.get_op_result_name(self, other)
58515856
self, other = self._align_for_op(other, align_asobject=True)
58525857

0 commit comments

Comments
 (0)