Skip to content

Commit de82b5e

Browse files
authored
PERF: _maybe_convert_value_to_local (#35070)
1 parent 18f821c commit de82b5e

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

asv_bench/benchmarks/tslibs/timestamp.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ def time_tz(self, tz, freq):
6363
def time_dayofweek(self, tz, freq):
6464
self.ts.dayofweek
6565

66-
def time_weekday_name(self, tz, freq):
67-
self.ts.day_name
68-
6966
def time_dayofyear(self, tz, freq):
7067
self.ts.dayofyear
7168

@@ -108,6 +105,9 @@ def time_microsecond(self, tz, freq):
108105
def time_month_name(self, tz, freq):
109106
self.ts.month_name()
110107

108+
def time_weekday_name(self, tz, freq):
109+
self.ts.day_name()
110+
111111

112112
class TimestampOps:
113113
params = [None, "US/Eastern", pytz.UTC, dateutil.tz.tzutc()]

pandas/_libs/tslibs/timestamps.pyx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ from pandas._libs.tslibs.nattype cimport NPY_NAT, c_NaT as NaT
4747
from pandas._libs.tslibs.np_datetime cimport (
4848
check_dts_bounds, npy_datetimestruct, dt64_to_dtstruct,
4949
cmp_scalar,
50+
pydatetime_to_dt64,
5051
)
5152
from pandas._libs.tslibs.np_datetime import OutOfBoundsDatetime
5253
from pandas._libs.tslibs.offsets cimport to_offset, is_tick_object, is_offset_object
@@ -376,9 +377,13 @@ cdef class _Timestamp(ABCTimestamp):
376377
"""Convert UTC i8 value to local i8 value if tz exists"""
377378
cdef:
378379
int64_t val
379-
val = self.value
380-
if self.tz is not None and not is_utc(self.tz):
381-
val = tz_convert_single(self.value, UTC, self.tz)
380+
tzinfo own_tz = self.tzinfo
381+
npy_datetimestruct dts
382+
383+
if own_tz is not None and not is_utc(own_tz):
384+
val = pydatetime_to_dt64(self, &dts) + self.nanosecond
385+
else:
386+
val = self.value
382387
return val
383388

384389
cdef bint _get_start_end_field(self, str field):

0 commit comments

Comments
 (0)