Skip to content

Commit 0d9712d

Browse files
committed
Make RESO constants global in period.pyx and reduce the number of loops in asv_benchmarks/period.py
1 parent 1c5a2ab commit 0d9712d

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

asv_bench/benchmarks/period.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from pandas import Period, PeriodIndex, date_range
1+
from pandas import PeriodIndex, date_range
22

33

44
class create_period_index_from_date_range(object):
55
goal_time = 0.2
66

77
def time_period_index(self):
88
# Simulate irregular PeriodIndex
9-
PeriodIndex(date_range('1985', periods=10000).to_pydatetime(), freq='D')
9+
PeriodIndex(date_range('1985', periods=1000).to_pydatetime(), freq='D')

pandas/src/period.pyx

+14-8
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ cdef bint PY2 = version_info[0] == 2
4444

4545
cdef int64_t NPY_NAT = util.get_nat()
4646

47+
cdef int US_RESO = frequencies.US_RESO
48+
cdef int MS_RESO = frequencies.MS_RESO
49+
cdef int S_RESO = frequencies.S_RESO
50+
cdef int T_RESO = frequencies.T_RESO
51+
cdef int H_RESO = frequencies.H_RESO
52+
cdef int D_RESO = frequencies.D_RESO
4753

4854
cdef extern from "period_helper.h":
4955
ctypedef struct date_info:
@@ -463,7 +469,7 @@ cpdef resolution(ndarray[int64_t] stamps, tz=None):
463469
cdef:
464470
Py_ssize_t i, n = len(stamps)
465471
pandas_datetimestruct dts
466-
int reso = frequencies.D_RESO, curr_reso
472+
int reso = D_RESO, curr_reso
467473

468474
if tz is not None:
469475
tz = maybe_get_tz(tz)
@@ -482,20 +488,20 @@ cpdef resolution(ndarray[int64_t] stamps, tz=None):
482488
cdef inline int _reso_stamp(pandas_datetimestruct *dts):
483489
if dts.us != 0:
484490
if dts.us % 1000 == 0:
485-
return frequencies.MS_RESO
486-
return frequencies.US_RESO
491+
return MS_RESO
492+
return US_RESO
487493
elif dts.sec != 0:
488-
return frequencies.S_RESO
494+
return S_RESO
489495
elif dts.min != 0:
490-
return frequencies.T_RESO
496+
return T_RESO
491497
elif dts.hour != 0:
492-
return frequencies.H_RESO
493-
return frequencies.D_RESO
498+
return H_RESO
499+
return D_RESO
494500

495501
cdef _reso_local(ndarray[int64_t] stamps, object tz):
496502
cdef:
497503
Py_ssize_t n = len(stamps)
498-
int reso = frequencies.D_RESO, curr_reso
504+
int reso = D_RESO, curr_reso
499505
ndarray[int64_t] trans, deltas, pos
500506
pandas_datetimestruct dts
501507

0 commit comments

Comments
 (0)