File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -324,6 +324,22 @@ def test_attrs_deepcopy(self):
324
324
assert result .attrs == df .attrs
325
325
assert result .attrs ["tags" ] is not df .attrs ["tags" ]
326
326
327
+ def test_attrs_binary_operations (self ):
328
+ # GH 51607
329
+ df_1 = DataFrame ({"A" : [2 , 3 ]})
330
+ df_2 = DataFrame ({"A" : [- 3 , 9 ]})
331
+ attrs = {"info" : "DataFrame" }
332
+ df_1 .attrs = attrs
333
+ assert (df_1 + df_2 ).attrs == attrs
334
+ assert (df_2 + df_1 ).attrs == attrs
335
+ assert (df_2 - df_1 ).attrs == attrs
336
+ assert (df_2 / df_1 ).attrs == attrs
337
+ assert (df_2 * df_1 ).attrs == attrs
338
+ assert (df_2 .add (df_1 )).attrs == attrs
339
+ assert (df_2 .sub (df_1 )).attrs == attrs
340
+ assert (df_2 .div (df_1 )).attrs == attrs
341
+ assert (df_2 .mul (df_1 )).attrs == attrs
342
+
327
343
@pytest .mark .parametrize ("allows_duplicate_labels" , [True , False , None ])
328
344
def test_set_flags (
329
345
self ,
Original file line number Diff line number Diff line change @@ -164,6 +164,22 @@ def test_attrs(self):
164
164
result = s + 1
165
165
assert result .attrs == {"version" : 1 }
166
166
167
+ def test_attrs_binary_operations (self ):
168
+ # GH 51607
169
+ s1 = Series ([2 , 5 ])
170
+ s2 = Series ([7 , - 1 ])
171
+ attrs = {"info" : "Series" }
172
+ s1 .attrs = attrs
173
+ assert (s1 + s2 ).attrs == attrs
174
+ assert (s2 + s1 ).attrs == attrs
175
+ assert (s2 - s1 ).attrs == attrs
176
+ assert (s2 / s1 ).attrs == attrs
177
+ assert (s2 * s1 ).attrs == attrs
178
+ assert (s2 .add (s1 )).attrs == attrs
179
+ assert (s2 .sub (s1 )).attrs == attrs
180
+ assert (s2 .div (s1 )).attrs == attrs
181
+ assert (s2 .mul (s1 )).attrs == attrs
182
+
167
183
@pytest .mark .xfail (
168
184
using_string_dtype () and not HAS_PYARROW , reason = "TODO(infer_string)"
169
185
)
You can’t perform that action at this time.
0 commit comments