@@ -36,12 +36,20 @@ from tslib cimport (
36
36
_nat_scalar_rules,
37
37
)
38
38
39
+ from pandas.tseries import frequencies
40
+
39
41
from sys import version_info
40
42
41
43
cdef bint PY2 = version_info[0 ] == 2
42
44
43
45
cdef int64_t NPY_NAT = util.get_nat()
44
46
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
45
53
46
54
cdef extern from " period_helper.h" :
47
55
ctypedef struct date_info:
@@ -476,12 +484,6 @@ cpdef resolution(ndarray[int64_t] stamps, tz=None):
476
484
reso = curr_reso
477
485
return reso
478
486
479
- US_RESO = 0
480
- MS_RESO = 1
481
- S_RESO = 2
482
- T_RESO = 3
483
- H_RESO = 4
484
- D_RESO = 5
485
487
486
488
cdef inline int _reso_stamp(pandas_datetimestruct * dts):
487
489
if dts.us != 0 :
@@ -662,17 +664,13 @@ cdef class Period(object):
662
664
def _maybe_convert_freq (cls , object freq ):
663
665
664
666
if isinstance (freq, compat.string_types):
665
- from pandas.tseries.frequencies import _period_alias_dict
666
667
freq = freq.upper()
667
- freq = _period_alias_dict.get(freq, freq)
668
+ freq = frequencies. _period_alias_dict.get(freq, freq)
668
669
elif isinstance (freq, (int , tuple )):
669
- from pandas.tseries.frequencies import get_freq_code as _gfc
670
- from pandas.tseries.frequencies import _get_freq_str
671
- code, stride = _gfc(freq)
672
- freq = _get_freq_str(code, stride)
670
+ code, stride = frequencies.get_freq_code(freq)
671
+ freq = frequencies._get_freq_str(code, stride)
673
672
674
- from pandas.tseries.frequencies import to_offset
675
- freq = to_offset(freq)
673
+ freq = frequencies.to_offset(freq)
676
674
677
675
if freq.n <= 0 :
678
676
raise ValueError (' Frequency must be positive, because it'
@@ -691,9 +689,6 @@ cdef class Period(object):
691
689
def __init__ (self , value = None , freq = None , ordinal = None ,
692
690
year = None , month = 1 , quarter = None , day = 1 ,
693
691
hour = 0 , minute = 0 , second = 0 ):
694
- from pandas.tseries import frequencies
695
- from pandas.tseries.frequencies import get_freq_code as _gfc
696
-
697
692
# freq points to a tuple (base, mult); base is one of the defined
698
693
# periods such as A, Q, etc. Every five minutes would be, e.g.,
699
694
# ('T', 5) but may be passed in as a string like '5T'
@@ -717,7 +712,7 @@ cdef class Period(object):
717
712
718
713
elif isinstance (value, Period):
719
714
other = value
720
- if freq is None or _gfc (freq) == _gfc (other.freq):
715
+ if freq is None or frequencies.get_freq_code (freq) == frequencies.get_freq_code (other.freq):
721
716
ordinal = other.ordinal
722
717
freq = other.freq
723
718
else :
@@ -758,7 +753,7 @@ cdef class Period(object):
758
753
msg = " Value must be Period, string, integer, or datetime"
759
754
raise ValueError (msg)
760
755
761
- base, mult = _gfc (freq)
756
+ base, mult = frequencies.get_freq_code (freq)
762
757
763
758
if ordinal is None :
764
759
self .ordinal = get_period_ordinal(dt.year, dt.month, dt.day,
@@ -771,7 +766,6 @@ cdef class Period(object):
771
766
772
767
def __richcmp__ (self , other , op ):
773
768
if isinstance (other, Period):
774
- from pandas.tseries.frequencies import get_freq_code as _gfc
775
769
if other.freq != self .freq:
776
770
msg = _DIFFERENT_FREQ.format(self .freqstr, other.freqstr)
777
771
raise IncompatibleFrequency(msg)
@@ -790,7 +784,6 @@ cdef class Period(object):
790
784
return hash ((self .ordinal, self .freq))
791
785
792
786
def _add_delta (self , other ):
793
- from pandas.tseries import frequencies
794
787
if isinstance (other, (timedelta, np.timedelta64, offsets.Tick, Timedelta)):
795
788
offset = frequencies.to_offset(self .freq.rule_code)
796
789
if isinstance (offset, offsets.Tick):
@@ -868,10 +861,9 @@ cdef class Period(object):
868
861
-------
869
862
resampled : Period
870
863
"""
871
- from pandas.tseries.frequencies import get_freq_code as _gfc
872
864
how = _validate_end_alias(how)
873
- base1, mult1 = _gfc (self .freq)
874
- base2, mult2 = _gfc (freq)
865
+ base1, mult1 = frequencies.get_freq_code (self .freq)
866
+ base2, mult2 = frequencies.get_freq_code (freq)
875
867
876
868
if self .ordinal == tslib.iNaT:
877
869
ordinal = self .ordinal
@@ -918,23 +910,20 @@ cdef class Period(object):
918
910
-------
919
911
Timestamp
920
912
"""
921
- from pandas.tseries import frequencies
922
- from pandas.tseries.frequencies import get_freq_code as _gfc
923
913
how = _validate_end_alias(how)
924
914
925
915
if freq is None :
926
- base, mult = _gfc (self .freq)
916
+ base, mult = frequencies.get_freq_code (self .freq)
927
917
freq = frequencies.get_to_timestamp_base(base)
928
918
929
- base, mult = _gfc (freq)
919
+ base, mult = frequencies.get_freq_code (freq)
930
920
val = self .asfreq(freq, how)
931
921
932
922
dt64 = period_ordinal_to_dt64(val.ordinal, base)
933
923
return Timestamp(dt64, tz = tz)
934
924
935
925
cdef _field(self , alias):
936
- from pandas.tseries.frequencies import get_freq_code as _gfc
937
- base, mult = _gfc(self .freq)
926
+ base, mult = frequencies.get_freq_code(self .freq)
938
927
return get_period_field(alias, self .ordinal, base)
939
928
940
929
property year :
@@ -996,8 +985,7 @@ cdef class Period(object):
996
985
return self .freq.freqstr
997
986
998
987
def __repr__ (self ):
999
- from pandas.tseries.frequencies import get_freq_code as _gfc
1000
- base, mult = _gfc(self .freq)
988
+ base, mult = frequencies.get_freq_code(self .freq)
1001
989
formatted = period_format(self .ordinal, base)
1002
990
return " Period('%s ', '%s ')" % (formatted, self .freqstr)
1003
991
@@ -1008,8 +996,7 @@ cdef class Period(object):
1008
996
Invoked by unicode(df) in py2 only. Yields a Unicode String in both
1009
997
py2/py3.
1010
998
"""
1011
- from pandas.tseries.frequencies import get_freq_code as _gfc
1012
- base, mult = _gfc(self .freq)
999
+ base, mult = frequencies.get_freq_code(self .freq)
1013
1000
formatted = period_format(self .ordinal, base)
1014
1001
value = (" %s " % formatted)
1015
1002
return value
@@ -1159,15 +1146,13 @@ cdef class Period(object):
1159
1146
>>> a.strftime('%b . %d , %Y was a %A ')
1160
1147
'Jan. 01, 2001 was a Monday'
1161
1148
"""
1162
- from pandas.tseries.frequencies import get_freq_code as _gfc
1163
- base, mult = _gfc(self .freq)
1149
+ base, mult = frequencies.get_freq_code(self .freq)
1164
1150
return period_format(self .ordinal, base, fmt)
1165
1151
1166
1152
1167
1153
def _ordinal_from_fields (year , month , quarter , day , hour , minute ,
1168
1154
second , freq ):
1169
- from pandas.tseries.frequencies import get_freq_code as _gfc
1170
- base, mult = _gfc(freq)
1155
+ base, mult = frequencies.get_freq_code(freq)
1171
1156
if quarter is not None :
1172
1157
year, month = _quarter_to_myear(year, quarter, freq)
1173
1158
@@ -1179,7 +1164,6 @@ def _quarter_to_myear(year, quarter, freq):
1179
1164
if quarter <= 0 or quarter > 4 :
1180
1165
raise ValueError (' Quarter must be 1 <= q <= 4' )
1181
1166
1182
- from pandas.tseries import frequencies
1183
1167
mnum = frequencies._month_numbers[frequencies._get_rule_month(freq)] + 1
1184
1168
month = (mnum + (quarter - 1 ) * 3 ) % 12 + 1
1185
1169
if month > mnum:
0 commit comments