Skip to content

Commit ebbe7bc

Browse files
committed
PERF: add vbench for DatetimeIndex unions/intersetions
1 parent a8f68f9 commit ebbe7bc

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

pandas/tslib.pyx

+10-10
Original file line numberDiff line numberDiff line change
@@ -475,11 +475,10 @@ cdef class _Timestamp(datetime):
475475
int64_t value, nanosecond
476476
object offset # frequency reference
477477

478-
def __hash__(self):
478+
def __hash__(_Timestamp self):
479479
if self.nanosecond:
480480
return hash(self.value)
481-
else:
482-
return datetime.__hash__(self)
481+
return datetime.__hash__(self)
483482

484483
def __richcmp__(_Timestamp self, object other, int op):
485484
cdef:
@@ -520,13 +519,14 @@ cdef class _Timestamp(datetime):
520519
self._assert_tzawareness_compat(other)
521520
return _cmp_scalar(self.value, ots.value, op)
522521

523-
cdef _compare_outside_nanorange(self, object other, int op):
522+
cdef bint _compare_outside_nanorange(_Timestamp self, datetime other,
523+
int op) except -1:
524524
cdef datetime dtval = self.to_datetime()
525525

526526
self._assert_tzawareness_compat(other)
527527

528528
if self.nanosecond == 0:
529-
return PyObject_RichCompare(dtval, other, op)
529+
return PyObject_RichCompareBool(dtval, other, op)
530530
else:
531531
if op == Py_EQ:
532532
return False
@@ -541,15 +541,15 @@ cdef class _Timestamp(datetime):
541541
elif op == Py_GE:
542542
return dtval >= other
543543

544-
cdef _assert_tzawareness_compat(self, object other):
544+
cdef void _assert_tzawareness_compat(_Timestamp self, object other):
545545
if self.tzinfo is None:
546546
if other.tzinfo is not None:
547-
raise Exception('Cannot compare tz-naive and '
548-
'tz-aware timestamps')
547+
raise ValueError('Cannot compare tz-naive and tz-aware '
548+
'timestamps')
549549
elif other.tzinfo is None:
550-
raise Exception('Cannot compare tz-naive and tz-aware timestamps')
550+
raise ValueError('Cannot compare tz-naive and tz-aware timestamps')
551551

552-
cpdef to_datetime(self):
552+
cpdef datetime to_datetime(_Timestamp self):
553553
cdef:
554554
pandas_datetimestruct dts
555555
_TSObject ts

vb_suite/index_object.py

+10
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@
2222
index_datetime_intersection = Benchmark("rng.intersection(rng2)", setup)
2323
index_datetime_union = Benchmark("rng.union(rng2)", setup)
2424

25+
setup = common_setup + """
26+
rng = date_range('1/1/2000', periods=10000, freq='T')
27+
rng2 = rng[:-1]
28+
"""
29+
30+
datetime_index_intersection = Benchmark("rng.intersection(rng2)", setup,
31+
start_date=datetime(2013, 9, 27))
32+
datetime_index_union = Benchmark("rng.union(rng2)", setup,
33+
start_date=datetime(2013, 9, 27))
34+
2535
# integers
2636
setup = common_setup + """
2737
N = 1000000

0 commit comments

Comments
 (0)