@@ -8088,8 +8088,7 @@ def _align_for_op(
8088
8088
8089
8089
Parameters
8090
8090
----------
8091
- left : DataFrame
8092
- right : Any
8091
+ other : Any
8093
8092
axis : int
8094
8093
flex : bool or None, default False
8095
8094
Whether this is a flex op, in which case we reindex.
@@ -8101,8 +8100,6 @@ def _align_for_op(
8101
8100
left : DataFrame
8102
8101
right : Any
8103
8102
"""
8104
- if not getattr (self , "attrs" , None ) and getattr (other , "attrs" , None ):
8105
- self .__finalize__ (other )
8106
8103
8107
8104
left , right = self , other
8108
8105
@@ -8203,7 +8200,6 @@ def to_series(right):
8203
8200
"`left, right = left.align(right, axis=1)` "
8204
8201
"before operating."
8205
8202
)
8206
-
8207
8203
left , right = left .align (
8208
8204
right ,
8209
8205
join = "outer" ,
@@ -8212,6 +8208,9 @@ def to_series(right):
8212
8208
)
8213
8209
right = left ._maybe_align_series_as_frame (right , axis )
8214
8210
8211
+ # Ensure attributes are consistent between the aligned and original objects
8212
+ if right .attrs != getattr (other , "attrs" , {}):
8213
+ right .attrs = getattr (other , "attrs" , {}).copy ()
8215
8214
return left , right
8216
8215
8217
8216
def _maybe_align_series_as_frame (self , series : Series , axis : AxisInt ):
0 commit comments