From 8731a88b276fd90e9ab4beda4266e44911a85ad2 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Mon, 12 Aug 2019 10:19:53 -0700 Subject: [PATCH] requested edit to comparison method --- pandas/core/ops/__init__.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pandas/core/ops/__init__.py b/pandas/core/ops/__init__.py index a56521b9c9fec..c243b28aedd3c 100644 --- a/pandas/core/ops/__init__.py +++ b/pandas/core/ops/__init__.py @@ -835,13 +835,12 @@ def wrapper(self, other, axis=None): elif isinstance(other, ABCSeries) and not self._indexed_same(other): raise ValueError("Can only compare identically-labeled Series objects") - elif ( - is_list_like(other) - and len(other) != len(self) - and not isinstance(other, frozenset) - ): - # TODO: why are we treating len-1 frozenset differently? - raise ValueError("Lengths must match to compare") + elif isinstance(other, (np.ndarray, ABCIndexClass, ABCSeries)): + # TODO: make this treatment consistent across ops and classes. + # We are not catching all listlikes here (e.g. frozenset, tuple) + # The ambiguous case is object-dtype. See GH#27803 + if len(self) != len(other): + raise ValueError("Lengths must match to compare") if is_categorical_dtype(self): # Dispatch to Categorical implementation; CategoricalIndex