@@ -36,6 +36,13 @@ from tslib cimport (
36
36
_nat_scalar_rules,
37
37
)
38
38
39
+ from pandas.tseries.frequencies import _period_alias_dict
40
+ from pandas.tseries.frequencies import _get_freq_str
41
+ from pandas.tseries.frequencies import to_offset
42
+ from pandas.tseries.frequencies import get_freq_code as _gfc
43
+ from pandas.tseries import frequencies
44
+ from pandas.tseries.constants import US_RESO, MS_RESO, S_RESO, T_RESO, H_RESO, D_RESO
45
+
39
46
from sys import version_info
40
47
41
48
cdef bint PY2 = version_info[0 ] == 2
@@ -476,12 +483,6 @@ cpdef resolution(ndarray[int64_t] stamps, tz=None):
476
483
reso = curr_reso
477
484
return reso
478
485
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
486
486
487
cdef inline int _reso_stamp(pandas_datetimestruct * dts):
487
488
if dts.us != 0 :
@@ -662,16 +663,12 @@ cdef class Period(object):
662
663
def _maybe_convert_freq (cls , object freq ):
663
664
664
665
if isinstance (freq, compat.string_types):
665
- from pandas.tseries.frequencies import _period_alias_dict
666
666
freq = freq.upper()
667
667
freq = _period_alias_dict.get(freq, freq)
668
668
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
669
code, stride = _gfc(freq)
672
670
freq = _get_freq_str(code, stride)
673
671
674
- from pandas.tseries.frequencies import to_offset
675
672
freq = to_offset(freq)
676
673
677
674
if freq.n <= 0 :
@@ -691,9 +688,6 @@ cdef class Period(object):
691
688
def __init__ (self , value = None , freq = None , ordinal = None ,
692
689
year = None , month = 1 , quarter = None , day = 1 ,
693
690
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
691
# freq points to a tuple (base, mult); base is one of the defined
698
692
# periods such as A, Q, etc. Every five minutes would be, e.g.,
699
693
# ('T', 5) but may be passed in as a string like '5T'
@@ -771,7 +765,6 @@ cdef class Period(object):
771
765
772
766
def __richcmp__ (self , other , op ):
773
767
if isinstance (other, Period):
774
- from pandas.tseries.frequencies import get_freq_code as _gfc
775
768
if other.freq != self .freq:
776
769
msg = _DIFFERENT_FREQ.format(self .freqstr, other.freqstr)
777
770
raise IncompatibleFrequency(msg)
@@ -790,7 +783,6 @@ cdef class Period(object):
790
783
return hash ((self .ordinal, self .freq))
791
784
792
785
def _add_delta (self , other ):
793
- from pandas.tseries import frequencies
794
786
if isinstance (other, (timedelta, np.timedelta64, offsets.Tick, Timedelta)):
795
787
offset = frequencies.to_offset(self .freq.rule_code)
796
788
if isinstance (offset, offsets.Tick):
@@ -868,7 +860,6 @@ cdef class Period(object):
868
860
-------
869
861
resampled : Period
870
862
"""
871
- from pandas.tseries.frequencies import get_freq_code as _gfc
872
863
how = _validate_end_alias(how)
873
864
base1, mult1 = _gfc(self .freq)
874
865
base2, mult2 = _gfc(freq)
@@ -918,8 +909,6 @@ cdef class Period(object):
918
909
-------
919
910
Timestamp
920
911
"""
921
- from pandas.tseries import frequencies
922
- from pandas.tseries.frequencies import get_freq_code as _gfc
923
912
how = _validate_end_alias(how)
924
913
925
914
if freq is None :
@@ -933,7 +922,6 @@ cdef class Period(object):
933
922
return Timestamp(dt64, tz = tz)
934
923
935
924
cdef _field(self , alias):
936
- from pandas.tseries.frequencies import get_freq_code as _gfc
937
925
base, mult = _gfc(self .freq)
938
926
return get_period_field(alias, self .ordinal, base)
939
927
@@ -996,7 +984,6 @@ cdef class Period(object):
996
984
return self .freq.freqstr
997
985
998
986
def __repr__ (self ):
999
- from pandas.tseries.frequencies import get_freq_code as _gfc
1000
987
base, mult = _gfc(self .freq)
1001
988
formatted = period_format(self .ordinal, base)
1002
989
return " Period('%s ', '%s ')" % (formatted, self .freqstr)
@@ -1008,7 +995,6 @@ cdef class Period(object):
1008
995
Invoked by unicode(df) in py2 only. Yields a Unicode String in both
1009
996
py2/py3.
1010
997
"""
1011
- from pandas.tseries.frequencies import get_freq_code as _gfc
1012
998
base, mult = _gfc(self .freq)
1013
999
formatted = period_format(self .ordinal, base)
1014
1000
value = (" %s " % formatted)
@@ -1159,14 +1145,12 @@ cdef class Period(object):
1159
1145
>>> a.strftime('%b . %d , %Y was a %A ')
1160
1146
'Jan. 01, 2001 was a Monday'
1161
1147
"""
1162
- from pandas.tseries.frequencies import get_freq_code as _gfc
1163
1148
base, mult = _gfc(self .freq)
1164
1149
return period_format(self .ordinal, base, fmt)
1165
1150
1166
1151
1167
1152
def _ordinal_from_fields (year , month , quarter , day , hour , minute ,
1168
1153
second , freq ):
1169
- from pandas.tseries.frequencies import get_freq_code as _gfc
1170
1154
base, mult = _gfc(freq)
1171
1155
if quarter is not None :
1172
1156
year, month = _quarter_to_myear(year, quarter, freq)
@@ -1179,7 +1163,6 @@ def _quarter_to_myear(year, quarter, freq):
1179
1163
if quarter <= 0 or quarter > 4 :
1180
1164
raise ValueError (' Quarter must be 1 <= q <= 4' )
1181
1165
1182
- from pandas.tseries import frequencies
1183
1166
mnum = frequencies._month_numbers[frequencies._get_rule_month(freq)] + 1
1184
1167
month = (mnum + (quarter - 1 ) * 3 ) % 12 + 1
1185
1168
if month > mnum:
0 commit comments