Skip to content

BUG: Bug in Timestamp comparisons with == and dtype of int64 (GH8058) #8070

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 19, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/v0.15.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ Bug Fixes
- Bug in ``combine_first`` with ``PeriodIndex`` data raises ``TypeError`` (:issue:`3367`)
- Bug in multi-index slicing with missing indexers (:issue:`7866`)
- Regression in multi-index indexing with a non-scalar type object (:issue:`7914`)

- Bug in Timestamp comparisons with ``==`` and dtype of int64 (:issue:`8058`)
- Bug in pickles contains ``DateOffset`` may raise ``AttributeError`` when ``normalize`` attribute is reffered internally (:issue:`7748`)

- Bug in pickle deserialization that failed for pre-0.14.1 containers with dup items trying to avoid ambiguity
Expand Down
29 changes: 29 additions & 0 deletions pandas/tseries/tests/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -3407,6 +3407,35 @@ def test_comparison(self):
self.assertTrue(other > val)
self.assertTrue(other >= val)

def test_compare_invalid(self):

# GH 8058
val = Timestamp('20130101 12:01:02')
self.assertFalse(val == 'foo')
self.assertFalse(val == 10.0)
self.assertFalse(val == 1)
self.assertFalse(val == long(1))
self.assertFalse(val == [])
self.assertFalse(val == {'foo' : 1})
self.assertFalse(val == np.float64(1))
self.assertFalse(val == np.int64(1))

self.assertTrue(val != 'foo')
self.assertTrue(val != 10.0)
self.assertTrue(val != 1)
self.assertTrue(val != long(1))
self.assertTrue(val != [])
self.assertTrue(val != {'foo' : 1})
self.assertTrue(val != np.float64(1))
self.assertTrue(val != np.int64(1))

# ops testing
df = DataFrame(randn(5,2))
a = df[0]
b = Series(randn(5))
b.name = Timestamp('2000-01-01')
tm.assert_series_equal(a / b, 1 / (b / a))

def test_cant_compare_tz_naive_w_aware(self):
tm._skip_if_no_pytz()
# #1404
Expand Down
6 changes: 6 additions & 0 deletions pandas/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,12 @@ cdef class _Timestamp(datetime):
if isinstance(other, np.datetime64):
other = Timestamp(other)
else:
if op == Py_EQ:
return False
elif op == Py_NE:
return True

# only allow ==, != ops
raise TypeError('Cannot compare type %r with type %r' %
(type(self).__name__,
type(other).__name__))
Expand Down