Skip to content

Commit 4cd6398

Browse files
committed
asv & some typing
1 parent 96d7a95 commit 4cd6398

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

asv_bench/benchmarks/timestamp.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from .pandas_vb_common import *
22
from pandas import to_timedelta, Timestamp
3+
import pytz
4+
import datetime
35

46

57
class TimestampProperties(object):
@@ -58,3 +60,24 @@ def time_is_leap_year(self):
5860

5961
def time_microsecond(self):
6062
self.ts.microsecond
63+
64+
65+
class TimestampOps(object):
66+
goal_time = 0.2
67+
68+
def setup(self):
69+
self.ts = Timestamp('2017-08-25 08:16:14')
70+
self.ts_tz = Timestamp('2017-08-25 08:16:14', tz='US/Eastern')
71+
72+
dt = datetime.datetime(2016, 3, 27, 1)
73+
self.tzinfo = pytz.timezone('CET').localize(dt, is_dst=False).tzinfo
74+
self.ts2 = Timestamp(dt)
75+
76+
def time_replace_tz(self):
77+
self.ts.replace(tzinfo=pytz.timezone('US/Eastern'))
78+
79+
def time_replace_across_dst(self):
80+
self.ts2.replace(tzinfo=self.tzinfo)
81+
82+
def time_replace_None(self):
83+
self.ts_tz.replace(tzinfo=None)

pandas/_libs/tslib.pyx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ def ints_to_pydatetime(ndarray[int64_t] arr, tz=None, freq=None, box=False):
144144

145145
cdef:
146146
Py_ssize_t i, n = len(arr)
147+
ndarray[int64_t] trans, deltas
147148
pandas_datetimestruct dts
148149
object dt
149150
int64_t value
@@ -707,8 +708,7 @@ class Timestamp(_Timestamp):
707708
value = self.value
708709
if _tzinfo is not None:
709710
value_tz = tz_convert_single(value, _tzinfo, 'UTC')
710-
offset = value - value_tz
711-
value += offset
711+
value += value - value_tz
712712

713713
# setup components
714714
pandas_datetime_to_datetimestruct(value, PANDAS_FR_ns, &dts)
@@ -1641,6 +1641,10 @@ cdef inline void _localize_tso(_TSObject obj, object tz):
16411641
"""
16421642
Take a TSObject in UTC and localizes to timezone tz.
16431643
"""
1644+
cdef:
1645+
ndarray[int64_t] trans, deltas
1646+
Py_ssize_t delta, posn
1647+
16441648
if _is_utc(tz):
16451649
obj.tzinfo = tz
16461650
elif _is_tzlocal(tz):
@@ -4174,7 +4178,7 @@ def tz_convert(ndarray[int64_t] vals, object tz1, object tz2):
41744178
return result
41754179

41764180

4177-
def tz_convert_single(int64_t val, object tz1, object tz2):
4181+
cpdef int64_t tz_convert_single(int64_t val, object tz1, object tz2):
41784182
"""
41794183
Convert the val (in i8) from timezone1 to timezone2
41804184
@@ -5178,6 +5182,7 @@ cdef inline int64_t _normalized_stamp(pandas_datetimestruct *dts) nogil:
51785182
def dates_normalized(ndarray[int64_t] stamps, tz=None):
51795183
cdef:
51805184
Py_ssize_t i, n = len(stamps)
5185+
ndarray[int64_t] trans, deltas
51815186
pandas_datetimestruct dts
51825187

51835188
if tz is None or _is_utc(tz):

0 commit comments

Comments
 (0)