@@ -663,27 +663,9 @@ def _comp_method_SERIES(cls, op, special):
663
663
"""
664
664
op_name = _get_op_name (op , special )
665
665
666
- def na_op (x , y ):
667
- # TODO:
668
- # should have guarantees on what x, y can be type-wise
669
- # Extension Dtypes are not called here
670
-
671
- if is_object_dtype (x .dtype ):
672
- result = comp_method_OBJECT_ARRAY (op , x , y )
673
-
674
- else :
675
- method = getattr (x , op_name )
676
- with np .errstate (all = "ignore" ):
677
- result = method (y )
678
- if result is NotImplemented :
679
- return invalid_comparison (x , y , op )
680
-
681
- return result
682
-
683
666
def wrapper (self , other ):
684
667
685
668
res_name = get_op_result_name (self , other )
686
- other = lib .item_from_zerodim (other )
687
669
688
670
# TODO: shouldn't we be applying finalize whenever
689
671
# not isinstance(other, ABCSeries)?
@@ -693,20 +675,19 @@ def wrapper(self, other):
693
675
else x
694
676
)
695
677
696
- if isinstance (other , list ):
697
- # TODO: same for tuples?
698
- other = np .asarray (other )
699
-
700
678
if isinstance (other , ABCDataFrame ): # pragma: no cover
701
679
# Defer to DataFrame implementation; fail early
702
680
return NotImplemented
703
681
704
682
if isinstance (other , ABCSeries ) and not self ._indexed_same (other ):
705
683
raise ValueError ("Can only compare identically-labeled Series objects" )
706
684
707
- elif isinstance (
708
- other , (np .ndarray , ABCExtensionArray , ABCIndexClass , ABCSeries )
709
- ):
685
+ other = lib .item_from_zerodim (other )
686
+ if isinstance (other , list ):
687
+ # TODO: same for tuples?
688
+ other = np .asarray (other )
689
+
690
+ if isinstance (other , (np .ndarray , ABCExtensionArray , ABCIndexClass )):
710
691
# TODO: make this treatment consistent across ops and classes.
711
692
# We are not catching all listlikes here (e.g. frozenset, tuple)
712
693
# The ambiguous case is object-dtype. See GH#27803
@@ -726,9 +707,17 @@ def wrapper(self, other):
726
707
else :
727
708
res_values = np .zeros (len (lvalues ), dtype = bool )
728
709
710
+ elif is_object_dtype (lvalues .dtype ):
711
+ res_values = comp_method_OBJECT_ARRAY (op , lvalues , rvalues )
712
+
729
713
else :
714
+ op_name = "__{op}__" .format (op = op .__name__ )
715
+ method = getattr (lvalues , op_name )
730
716
with np .errstate (all = "ignore" ):
731
- res_values = na_op (lvalues , rvalues )
717
+ res_values = method (rvalues )
718
+
719
+ if res_values is NotImplemented :
720
+ res_values = invalid_comparison (lvalues , rvalues , op )
732
721
if is_scalar (res_values ):
733
722
raise TypeError (
734
723
"Could not compare {typ} type with Series" .format (typ = type (rvalues ))
0 commit comments