Skip to content

Commit 12a39bb

Browse files
committed
Merge pull request #8070 from jreback/timestamp_equal
BUG: Bug in Timestamp comparisons with == and dtype of int64 (GH8058)
2 parents 8ec6a5f + c8f457a commit 12a39bb

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

doc/source/v0.15.0.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ Bug Fixes
498498
- Bug in ``combine_first`` with ``PeriodIndex`` data raises ``TypeError`` (:issue:`3367`)
499499
- Bug in multi-index slicing with missing indexers (:issue:`7866`)
500500
- Regression in multi-index indexing with a non-scalar type object (:issue:`7914`)
501-
501+
- Bug in Timestamp comparisons with ``==`` and dtype of int64 (:issue:`8058`)
502502
- Bug in pickles contains ``DateOffset`` may raise ``AttributeError`` when ``normalize`` attribute is reffered internally (:issue:`7748`)
503503

504504
- Bug in pickle deserialization that failed for pre-0.14.1 containers with dup items trying to avoid ambiguity

pandas/tseries/tests/test_timeseries.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3407,6 +3407,35 @@ def test_comparison(self):
34073407
self.assertTrue(other > val)
34083408
self.assertTrue(other >= val)
34093409

3410+
def test_compare_invalid(self):
3411+
3412+
# GH 8058
3413+
val = Timestamp('20130101 12:01:02')
3414+
self.assertFalse(val == 'foo')
3415+
self.assertFalse(val == 10.0)
3416+
self.assertFalse(val == 1)
3417+
self.assertFalse(val == long(1))
3418+
self.assertFalse(val == [])
3419+
self.assertFalse(val == {'foo' : 1})
3420+
self.assertFalse(val == np.float64(1))
3421+
self.assertFalse(val == np.int64(1))
3422+
3423+
self.assertTrue(val != 'foo')
3424+
self.assertTrue(val != 10.0)
3425+
self.assertTrue(val != 1)
3426+
self.assertTrue(val != long(1))
3427+
self.assertTrue(val != [])
3428+
self.assertTrue(val != {'foo' : 1})
3429+
self.assertTrue(val != np.float64(1))
3430+
self.assertTrue(val != np.int64(1))
3431+
3432+
# ops testing
3433+
df = DataFrame(randn(5,2))
3434+
a = df[0]
3435+
b = Series(randn(5))
3436+
b.name = Timestamp('2000-01-01')
3437+
tm.assert_series_equal(a / b, 1 / (b / a))
3438+
34103439
def test_cant_compare_tz_naive_w_aware(self):
34113440
tm._skip_if_no_pytz()
34123441
# #1404

pandas/tslib.pyx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,12 @@ cdef class _Timestamp(datetime):
710710
if isinstance(other, np.datetime64):
711711
other = Timestamp(other)
712712
else:
713+
if op == Py_EQ:
714+
return False
715+
elif op == Py_NE:
716+
return True
717+
718+
# only allow ==, != ops
713719
raise TypeError('Cannot compare type %r with type %r' %
714720
(type(self).__name__,
715721
type(other).__name__))

0 commit comments

Comments
 (0)