Skip to content

Commit 2990c1d

Browse files
authored
PERF: type tz kwarg in create_timestamp_from_ts (#35067)
1 parent ca3272d commit 2990c1d

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

pandas/_libs/tslib.pyx

+10-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ from cpython.datetime cimport (
88
datetime,
99
time,
1010
timedelta,
11+
tzinfo,
1112
)
1213
# import datetime C API
1314
PyDateTime_IMPORT
@@ -77,9 +78,9 @@ from pandas._libs.missing cimport checknull_with_nat_and_na
7778
cdef inline object create_datetime_from_ts(
7879
int64_t value,
7980
npy_datetimestruct dts,
80-
object tz,
81+
tzinfo tz,
8182
object freq,
82-
bint fold
83+
bint fold,
8384
):
8485
"""
8586
Convenience routine to construct a datetime.datetime from its parts.
@@ -92,7 +93,7 @@ cdef inline object create_datetime_from_ts(
9293
cdef inline object create_date_from_ts(
9394
int64_t value,
9495
npy_datetimestruct dts,
95-
object tz,
96+
tzinfo tz,
9697
object freq,
9798
bint fold
9899
):
@@ -106,7 +107,7 @@ cdef inline object create_date_from_ts(
106107
cdef inline object create_time_from_ts(
107108
int64_t value,
108109
npy_datetimestruct dts,
109-
object tz,
110+
tzinfo tz,
110111
object freq,
111112
bint fold
112113
):
@@ -120,7 +121,7 @@ cdef inline object create_time_from_ts(
120121
@cython.boundscheck(False)
121122
def ints_to_pydatetime(
122123
const int64_t[:] arr,
123-
object tz=None,
124+
tzinfo tz=None,
124125
object freq=None,
125126
bint fold=False,
126127
str box="datetime"
@@ -162,7 +163,7 @@ def ints_to_pydatetime(
162163
str typ
163164
int64_t value, delta, local_value
164165
ndarray[object] result = np.empty(n, dtype=object)
165-
object (*func_create)(int64_t, npy_datetimestruct, object, object, bint)
166+
object (*func_create)(int64_t, npy_datetimestruct, tzinfo, object, bint)
166167

167168
if box == "date":
168169
assert (tz is None), "tz should be None when converting to date"
@@ -178,7 +179,9 @@ def ints_to_pydatetime(
178179
elif box == "datetime":
179180
func_create = create_datetime_from_ts
180181
else:
181-
raise ValueError("box must be one of 'datetime', 'date', 'time' or 'timestamp'")
182+
raise ValueError(
183+
"box must be one of 'datetime', 'date', 'time' or 'timestamp'"
184+
)
182185

183186
if is_utc(tz) or tz is None:
184187
for i in range(n):

pandas/_libs/tslibs/timestamps.pxd

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from cpython.datetime cimport datetime
1+
from cpython.datetime cimport datetime, tzinfo
22

33
from numpy cimport int64_t
44

@@ -8,7 +8,7 @@ from pandas._libs.tslibs.np_datetime cimport npy_datetimestruct
88

99
cdef object create_timestamp_from_ts(int64_t value,
1010
npy_datetimestruct dts,
11-
object tz, object freq, bint fold)
11+
tzinfo tz, object freq, bint fold)
1212

1313

1414
cdef class _Timestamp(ABCTimestamp):

pandas/_libs/tslibs/timestamps.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ _no_input = object()
6969

7070
cdef inline object create_timestamp_from_ts(int64_t value,
7171
npy_datetimestruct dts,
72-
object tz, object freq, bint fold):
72+
tzinfo tz, object freq, bint fold):
7373
""" convenience routine to construct a Timestamp from its parts """
7474
cdef _Timestamp ts_base
7575
ts_base = _Timestamp.__new__(Timestamp, dts.year, dts.month,

0 commit comments

Comments
 (0)