@@ -8088,8 +8088,7 @@ def _align_for_op(
80888088
80898089 Parameters
80908090 ----------
8091- left : DataFrame
8092- right : Any
8091+ other : Any
80938092 axis : int
80948093 flex : bool or None, default False
80958094 Whether this is a flex op, in which case we reindex.
@@ -8101,8 +8100,6 @@ def _align_for_op(
81018100 left : DataFrame
81028101 right : Any
81038102 """
8104- if not getattr (self , "attrs" , None ) and getattr (other , "attrs" , None ):
8105- self .__finalize__ (other )
81068103
81078104 left , right = self , other
81088105
@@ -8203,7 +8200,6 @@ def to_series(right):
82038200 "`left, right = left.align(right, axis=1)` "
82048201 "before operating."
82058202 )
8206-
82078203 left , right = left .align (
82088204 right ,
82098205 join = "outer" ,
@@ -8212,6 +8208,9 @@ def to_series(right):
82128208 )
82138209 right = left ._maybe_align_series_as_frame (right , axis )
82148210
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 ()
82158214 return left , right
82168215
82178216 def _maybe_align_series_as_frame (self , series : Series , axis : AxisInt ):
0 commit comments