@@ -144,6 +144,7 @@ def ints_to_pydatetime(ndarray[int64_t] arr, tz=None, freq=None, box=False):
144
144
145
145
cdef:
146
146
Py_ssize_t i, n = len (arr)
147
+ ndarray[int64_t] trans, deltas
147
148
pandas_datetimestruct dts
148
149
object dt
149
150
int64_t value
@@ -433,8 +434,9 @@ class Timestamp(_Timestamp):
433
434
434
435
def _round (self , freq , rounder ):
435
436
436
- cdef int64_t unit
437
- cdef object result, value
437
+ cdef:
438
+ int64_t unit, r, value, buff = 1000000
439
+ object result
438
440
439
441
from pandas.tseries.frequencies import to_offset
440
442
unit = to_offset(freq).nanos
@@ -445,16 +447,15 @@ class Timestamp(_Timestamp):
445
447
if unit < 1000 and unit % 1000 != 0 :
446
448
# for nano rounding, work with the last 6 digits separately
447
449
# due to float precision
448
- buff = 1000000
449
- result = (buff * (value // buff) + unit *
450
- (rounder((value % buff) / float (unit))).astype(' i8' ))
450
+ r = (buff * (value // buff) + unit *
451
+ (rounder((value % buff) / float (unit))).astype(' i8' ))
451
452
elif unit >= 1000 and unit % 1000 != 0 :
452
453
msg = ' Precision will be lost using frequency: {}'
453
454
warnings.warn(msg.format(freq))
454
- result = (unit * rounder(value / float (unit)).astype(' i8' ))
455
+ r = (unit * rounder(value / float (unit)).astype(' i8' ))
455
456
else :
456
- result = (unit * rounder(value / float (unit)).astype(' i8' ))
457
- result = Timestamp(result , unit = ' ns' )
457
+ r = (unit * rounder(value / float (unit)).astype(' i8' ))
458
+ result = Timestamp(r , unit = ' ns' )
458
459
if self .tz is not None :
459
460
result = result.tz_localize(self .tz)
460
461
return result
@@ -700,15 +701,15 @@ class Timestamp(_Timestamp):
700
701
cdef:
701
702
pandas_datetimestruct dts
702
703
int64_t value, value_tz, offset
703
- object _tzinfo, result, k, v, ts_input
704
+ object _tzinfo, result, k, v
705
+ datetime ts_input
704
706
705
707
# set to naive if needed
706
708
_tzinfo = self .tzinfo
707
709
value = self .value
708
710
if _tzinfo is not None :
709
711
value_tz = tz_convert_single(value, _tzinfo, ' UTC' )
710
- offset = value - value_tz
711
- value += offset
712
+ value += value - value_tz
712
713
713
714
# setup components
714
715
pandas_datetime_to_datetimestruct(value, PANDAS_FR_ns, & dts)
@@ -1191,7 +1192,7 @@ cdef class _Timestamp(datetime):
1191
1192
return np.datetime64(self .value, ' ns' )
1192
1193
1193
1194
def __add__ (self , other ):
1194
- cdef int64_t other_int
1195
+ cdef int64_t other_int, nanos
1195
1196
1196
1197
if is_timedelta64_object(other):
1197
1198
other_int = other.astype(' timedelta64[ns]' ).view(' i8' )
@@ -1641,6 +1642,10 @@ cdef inline void _localize_tso(_TSObject obj, object tz):
1641
1642
"""
1642
1643
Take a TSObject in UTC and localizes to timezone tz.
1643
1644
"""
1645
+ cdef:
1646
+ ndarray[int64_t] trans, deltas
1647
+ Py_ssize_t delta, posn
1648
+
1644
1649
if _is_utc(tz):
1645
1650
obj.tzinfo = tz
1646
1651
elif _is_tzlocal(tz):
@@ -1692,7 +1697,7 @@ cdef inline void _localize_tso(_TSObject obj, object tz):
1692
1697
obj.tzinfo = tz
1693
1698
1694
1699
1695
- def _localize_pydatetime (object dt , object tz ):
1700
+ cpdef inline object _localize_pydatetime(object dt, object tz):
1696
1701
"""
1697
1702
Take a datetime/Timestamp in UTC and localizes to timezone tz.
1698
1703
"""
@@ -3929,7 +3934,7 @@ for _maybe_method_name in dir(NaTType):
3929
3934
# Conversion routines
3930
3935
3931
3936
3932
- def _delta_to_nanoseconds (delta ):
3937
+ cpdef int64_t _delta_to_nanoseconds(delta):
3933
3938
if isinstance (delta, np.ndarray):
3934
3939
return delta.astype(' m8[ns]' ).astype(' int64' )
3935
3940
if hasattr (delta, ' nanos' ):
@@ -4174,7 +4179,7 @@ def tz_convert(ndarray[int64_t] vals, object tz1, object tz2):
4174
4179
return result
4175
4180
4176
4181
4177
- def tz_convert_single (int64_t val , object tz1 , object tz2 ):
4182
+ cpdef int64_t tz_convert_single(int64_t val, object tz1, object tz2):
4178
4183
"""
4179
4184
Convert the val (in i8) from timezone1 to timezone2
4180
4185
@@ -5178,6 +5183,7 @@ cdef inline int64_t _normalized_stamp(pandas_datetimestruct *dts) nogil:
5178
5183
def dates_normalized (ndarray[int64_t] stamps , tz = None ):
5179
5184
cdef:
5180
5185
Py_ssize_t i, n = len (stamps)
5186
+ ndarray[int64_t] trans, deltas
5181
5187
pandas_datetimestruct dts
5182
5188
5183
5189
if tz is None or _is_utc(tz):
0 commit comments