Skip to content

Commit 0a36dd5

Browse files
committed
BUG: raise TypeError when comparing None with float series, unit test to close #1079
1 parent 2d3a9b3 commit 0a36dd5

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

pandas/core/series.py

+4
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ def wrapper(self, other):
115115
return NotImplemented
116116
else:
117117
# scalars
118+
res = na_op(self.values, other)
119+
if np.isscalar(res):
120+
raise TypeError('Could not compare %s type with Series'
121+
% type(other))
118122
return Series(na_op(self.values, other),
119123
index=self.index, name=self.name)
120124
return wrapper

pandas/tests/test_frame.py

+6
Original file line numberDiff line numberDiff line change
@@ -2544,6 +2544,12 @@ def test_string_comparison(self):
25442544
assert_frame_equal(df[mask_b], df.ix[0:0,:])
25452545
assert_frame_equal(df[-mask_b], df.ix[1:1,:])
25462546

2547+
def test_float_none_comparison(self):
2548+
df = DataFrame(np.random.randn(8, 3), index=range(8),
2549+
columns=['A', 'B', 'C'])
2550+
2551+
self.assertRaises(TypeError, df.__eq__, None)
2552+
25472553
def test_to_csv_from_csv(self):
25482554
path = '__tmp__'
25492555

pandas/tests/test_series.py

+5
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ def test_comparisons(self):
164164

165165
assert_almost_equal(result, expected)
166166

167+
def test_none_comparison(self):
168+
# bug brought up by #1079
169+
s = Series(np.random.randn(10), index=range(0, 20, 2))
170+
self.assertRaises(TypeError, s.__eq__, None)
171+
167172
def test_sum_zero(self):
168173
arr = np.array([])
169174
self.assert_(nanops.nansum(arr) == 0)

0 commit comments

Comments
 (0)