Skip to content

Commit bd54c9e

Browse files
committed
tweak Series comparison so type check doesn't have to be done more than once
1 parent 78547a9 commit bd54c9e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

pandas/core/series.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,6 @@ def na_op(x, y):
117117
else:
118118
result = lib.scalar_compare(x, y, op)
119119
else:
120-
if (isinstance(x, np.ndarray) and
121-
isinstance(y, np.ndarray) and
122-
len(x) != len(y)):
123-
raise ValueError('Array lengths must equal to compare')
124120
result = op(x, y)
125121

126122
return result
@@ -130,11 +126,15 @@ def wrapper(self, other):
130126

131127
if isinstance(other, Series):
132128
name = _maybe_match_name(self, other)
129+
if len(self) != len(other):
130+
raise ValueError('Series lengths must match to compare')
133131
return Series(na_op(self.values, other.values),
134132
index=self.index, name=name)
135133
elif isinstance(other, DataFrame): # pragma: no cover
136134
return NotImplemented
137135
elif isinstance(other, np.ndarray):
136+
if len(self) != len(other):
137+
raise ValueError('Lengths must match to compare')
138138
return Series(na_op(self.values, np.asarray(other)),
139139
index=self.index, name=self.name)
140140
else:

0 commit comments

Comments
 (0)