@@ -574,6 +574,9 @@ def _construct_result(left, result, index, name, dtype=None):
574
574
"""
575
575
out = left ._constructor (result , index = index , dtype = dtype )
576
576
out = out .__finalize__ (left )
577
+
578
+ # Set the result's name after __finalize__ is called because __finalize__
579
+ # would set it back to self.name
577
580
out .name = name
578
581
return out
579
582
@@ -628,14 +631,6 @@ def wrapper(self, other):
628
631
629
632
res_name = get_op_result_name (self , other )
630
633
631
- # TODO: shouldn't we be applying finalize whenever
632
- # not isinstance(other, ABCSeries)?
633
- finalizer = (
634
- lambda x : x .__finalize__ (self )
635
- if isinstance (other , (np .ndarray , ABCIndexClass ))
636
- else x
637
- )
638
-
639
634
if isinstance (other , ABCDataFrame ): # pragma: no cover
640
635
# Defer to DataFrame implementation; fail early
641
636
return NotImplemented
@@ -648,13 +643,7 @@ def wrapper(self, other):
648
643
649
644
res_values = comparison_op (lvalues , rvalues , op )
650
645
651
- result = self ._constructor (res_values , index = self .index )
652
- result = finalizer (result )
653
-
654
- # Set the result's name after finalizer is called because finalizer
655
- # would set it back to self.name
656
- result .name = res_name
657
- return result
646
+ return _construct_result (self , res_values , index = self .index , name = res_name )
658
647
659
648
wrapper .__name__ = op_name
660
649
return wrapper
@@ -671,14 +660,6 @@ def wrapper(self, other):
671
660
self , other = _align_method_SERIES (self , other , align_asobject = True )
672
661
res_name = get_op_result_name (self , other )
673
662
674
- # TODO: shouldn't we be applying finalize whenever
675
- # not isinstance(other, ABCSeries)?
676
- finalizer = (
677
- lambda x : x .__finalize__ (self )
678
- if not isinstance (other , (ABCSeries , ABCIndexClass ))
679
- else x
680
- )
681
-
682
663
if isinstance (other , ABCDataFrame ):
683
664
# Defer to DataFrame implementation; fail early
684
665
return NotImplemented
@@ -687,8 +668,7 @@ def wrapper(self, other):
687
668
rvalues = extract_array (other , extract_numpy = True )
688
669
689
670
res_values = logical_op (lvalues , rvalues , op )
690
- result = self ._constructor (res_values , index = self .index , name = res_name )
691
- return finalizer (result )
671
+ return _construct_result (self , res_values , index = self .index , name = res_name )
692
672
693
673
wrapper .__name__ = op_name
694
674
return wrapper
0 commit comments