@@ -31,8 +31,6 @@ from pandas._libs.tslibs.util cimport (
31
31
is_float_object,
32
32
)
33
33
34
- from pandas._libs.tslibs.base cimport ABCTimestamp
35
-
36
34
from pandas._libs.tslibs.ccalendar import (
37
35
MONTH_ALIASES, MONTH_TO_CAL_NUM, weekday_to_int, int_to_weekday,
38
36
)
@@ -50,7 +48,9 @@ from pandas._libs.tslibs.tzconversion cimport tz_convert_single
50
48
51
49
from .dtypes cimport PeriodDtypeCode
52
50
from .timedeltas cimport delta_to_nanoseconds
53
-
51
+ from .timedeltas import Timedelta
52
+ from .timestamps cimport _Timestamp
53
+ from .timestamps import Timestamp
54
54
55
55
# ---------------------------------------------------------------------
56
56
# Misc Helpers
@@ -64,7 +64,7 @@ cdef bint is_tick_object(object obj):
64
64
65
65
66
66
cdef datetime _as_datetime(datetime obj):
67
- if isinstance (obj, ABCTimestamp ):
67
+ if isinstance (obj, _Timestamp ):
68
68
return obj.to_pydatetime()
69
69
return obj
70
70
@@ -73,7 +73,7 @@ cdef bint _is_normalized(datetime dt):
73
73
if dt.hour != 0 or dt.minute != 0 or dt.second != 0 or dt.microsecond != 0 :
74
74
# Regardless of whether dt is datetime vs Timestamp
75
75
return False
76
- if isinstance (dt, ABCTimestamp ):
76
+ if isinstance (dt, _Timestamp ):
77
77
return dt.nanosecond == 0
78
78
return True
79
79
@@ -108,7 +108,6 @@ def apply_wraps(func):
108
108
# not play nicely with cython class methods
109
109
110
110
def wrapper (self , other ):
111
- from pandas import Timestamp
112
111
113
112
if other is NaT:
114
113
return NaT
@@ -585,7 +584,6 @@ cdef class BaseOffset:
585
584
TimeStamp
586
585
Rolled timestamp if not on offset, otherwise unchanged timestamp.
587
586
"""
588
- from pandas import Timestamp
589
587
dt = Timestamp(dt)
590
588
if not self .is_on_offset(dt):
591
589
dt = dt - type (self )(1 , normalize = self .normalize, ** self .kwds)
@@ -600,7 +598,6 @@ cdef class BaseOffset:
600
598
TimeStamp
601
599
Rolled timestamp if not on offset, otherwise unchanged timestamp.
602
600
"""
603
- from pandas import Timestamp
604
601
dt = Timestamp(dt)
605
602
if not self .is_on_offset(dt):
606
603
dt = dt + type (self )(1 , normalize = self .normalize, ** self .kwds)
@@ -767,7 +764,6 @@ cdef class Tick(SingleConstructorOffset):
767
764
768
765
@property
769
766
def delta(self ):
770
- from .timedeltas import Timedelta
771
767
return self .n * Timedelta(self ._nanos_inc)
772
768
773
769
@property
@@ -854,7 +850,7 @@ cdef class Tick(SingleConstructorOffset):
854
850
855
851
def apply (self , other ):
856
852
# Timestamp can handle tz and nano sec, thus no need to use apply_wraps
857
- if isinstance (other, ABCTimestamp ):
853
+ if isinstance (other, _Timestamp ):
858
854
859
855
# GH#15126
860
856
# in order to avoid a recursive
@@ -869,7 +865,6 @@ cdef class Tick(SingleConstructorOffset):
869
865
return NaT
870
866
elif is_datetime64_object(other) or PyDate_Check(other):
871
867
# PyDate_Check includes date, datetime
872
- from pandas import Timestamp
873
868
return Timestamp(other) + self
874
869
875
870
if PyDelta_Check(other):
@@ -1028,7 +1023,6 @@ cdef class RelativeDeltaOffset(BaseOffset):
1028
1023
# bring tz back from UTC calculation
1029
1024
other = localize_pydatetime(other, tzinfo)
1030
1025
1031
- from .timestamps import Timestamp
1032
1026
return Timestamp(other)
1033
1027
else :
1034
1028
return other + timedelta(self .n)
@@ -1077,7 +1071,6 @@ cdef class RelativeDeltaOffset(BaseOffset):
1077
1071
if k in [" days" , " hours" , " minutes" , " seconds" , " microseconds" ]
1078
1072
}
1079
1073
if timedelta_kwds:
1080
- from .timedeltas import Timedelta
1081
1074
delta = Timedelta(** timedelta_kwds)
1082
1075
index = index + (self .n * delta)
1083
1076
return index
@@ -2291,7 +2284,6 @@ cdef class SemiMonthOffset(SingleConstructorOffset):
2291
2284
@apply_index_wraps
2292
2285
def apply_index (self , dtindex ):
2293
2286
# determine how many days away from the 1st of the month we are
2294
- from pandas import Timedelta
2295
2287
2296
2288
dti = dtindex
2297
2289
i8other = dtindex.asi8
@@ -2394,8 +2386,6 @@ cdef class SemiMonthEnd(SemiMonthOffset):
2394
2386
-------
2395
2387
result : DatetimeIndex
2396
2388
"""
2397
- from pandas import Timedelta
2398
-
2399
2389
nanos = (roll % 2 ) * Timedelta(days = self .day_of_month).value
2400
2390
dtindex += nanos.astype(" timedelta64[ns]" )
2401
2391
return dtindex + Timedelta(days = - 1 )
@@ -2453,7 +2443,6 @@ cdef class SemiMonthBegin(SemiMonthOffset):
2453
2443
-------
2454
2444
result : DatetimeIndex
2455
2445
"""
2456
- from pandas import Timedelta
2457
2446
nanos = (roll % 2 ) * Timedelta(days = self .day_of_month - 1 ).value
2458
2447
return dtindex + nanos.astype(" timedelta64[ns]" )
2459
2448
@@ -2545,7 +2534,6 @@ cdef class Week(SingleConstructorOffset):
2545
2534
-------
2546
2535
result : DatetimeIndex
2547
2536
"""
2548
- from pandas import Timedelta
2549
2537
from .frequencies import get_freq_code # TODO: avoid circular import
2550
2538
2551
2539
i8other = dtindex.asi8
@@ -2847,8 +2835,6 @@ cdef class FY5253(FY5253Mixin):
2847
2835
2848
2836
@apply_wraps
2849
2837
def apply (self , other ):
2850
- from pandas import Timestamp
2851
-
2852
2838
norm = Timestamp(other).normalize()
2853
2839
2854
2840
n = self .n
@@ -3069,8 +3055,6 @@ cdef class FY5253Quarter(FY5253Mixin):
3069
3055
num_qtrs : int
3070
3056
tdelta : Timedelta
3071
3057
"""
3072
- from pandas import Timestamp, Timedelta
3073
-
3074
3058
num_qtrs = 0
3075
3059
3076
3060
norm = Timestamp(other).tz_localize(None )
@@ -3101,7 +3085,6 @@ cdef class FY5253Quarter(FY5253Mixin):
3101
3085
@apply_wraps
3102
3086
def apply (self , other ):
3103
3087
# Note: self.n == 0 is not allowed.
3104
- from pandas import Timedelta
3105
3088
3106
3089
n = self .n
3107
3090
@@ -3141,8 +3124,6 @@ cdef class FY5253Quarter(FY5253Mixin):
3141
3124
def year_has_extra_week (self , dt: datetime ) -> bool:
3142
3125
# Avoid round-down errors --> normalize to get
3143
3126
# e.g. '370D' instead of '360D23H'
3144
- from pandas import Timestamp
3145
-
3146
3127
norm = Timestamp(dt).normalize().tz_localize(None )
3147
3128
3148
3129
next_year_end = self ._offset.rollforward(norm)
@@ -3621,9 +3602,6 @@ cpdef to_offset(freq):
3621
3602
>>> to_offset(Hour())
3622
3603
<Hour>
3623
3604
"""
3624
- # TODO: avoid runtime imports
3625
- from pandas._libs.tslibs.timedeltas import Timedelta
3626
-
3627
3605
if freq is None :
3628
3606
return None
3629
3607
0 commit comments