Skip to content

Commit 78547a9

Browse files
committed
BUG: series comp non-object dtype does not raise error on diff length
1 parent 6dfa5fc commit 78547a9

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

pandas/core/series.py

+4
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ 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')
120124
result = op(x, y)
121125

122126
return result

pandas/tests/test_series.py

+4
Original file line numberDiff line numberDiff line change
@@ -1598,6 +1598,10 @@ def test_comparison_different_length(self):
15981598
b = Series(['b', 'a'])
15991599
self.assertRaises(ValueError, a.__lt__, b)
16001600

1601+
a = Series([1, 2])
1602+
b = Series([2, 3, 4])
1603+
self.assertRaises(ValueError, a.__eq__, b)
1604+
16011605
def test_between(self):
16021606
s = Series(bdate_range('1/1/2000', periods=20).asobject)
16031607
s[::2] = np.nan

0 commit comments

Comments
 (0)