Skip to content

Commit 38efbaa

Browse files
committed
Fix binary operators on attrs for Series and DataFrame
1 parent eb05b13 commit 38efbaa

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

pandas/core/base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,6 +1466,9 @@ def _arith_method(self, other, op):
14661466
with np.errstate(all="ignore"):
14671467
result = ops.arithmetic_op(lvalues, rvalues, op)
14681468

1469+
if not self.attrs and other.attrs:
1470+
self.attrs = other.attrs
1471+
14691472
return self._construct_result(result, name=res_name)
14701473

14711474
def _construct_result(self, result, name):

pandas/core/frame.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7830,6 +7830,10 @@ def _arith_method(self, other, op):
78307830

78317831
with np.errstate(all="ignore"):
78327832
new_data = self._dispatch_frame_op(other, op, axis=axis)
7833+
7834+
if not self.attrs and other.attrs:
7835+
self.attrs = other.attrs
7836+
78337837
return self._construct_result(new_data)
78347838

78357839
_logical_method = _arith_method
@@ -8185,6 +8189,9 @@ def _flex_arith_method(
81858189

81868190
new_data = self._dispatch_frame_op(other, op)
81878191

8192+
if not self.attrs and other.attrs:
8193+
self.attrs = other.attrs
8194+
81888195
return self._construct_result(new_data)
81898196

81908197
def _construct_result(self, result) -> DataFrame:

pandas/core/series.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5916,6 +5916,10 @@ def _binop(self, other: Series, func, level=None, fill_value=None) -> Series:
59165916
result = func(this_vals, other_vals)
59175917

59185918
name = ops.get_op_result_name(self, other)
5919+
5920+
if not this.attrs and other.attrs:
5921+
this.attrs = other.attrs
5922+
59195923
out = this._construct_result(result, name)
59205924
return cast(Series, out)
59215925

0 commit comments

Comments
 (0)