Skip to content

Commit a95116d

Browse files
authored
CLN: stricter typing in tzconversion (#34504)
1 parent b5832bf commit a95116d

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

pandas/_libs/tslibs/tzconversion.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ from numpy cimport int64_t
33

44

55
cdef int64_t tz_convert_utc_to_tzlocal(int64_t utc_val, tzinfo tz, bint* fold=*)
6-
cpdef int64_t tz_convert_single(int64_t val, object tz1, object tz2)
6+
cpdef int64_t tz_convert_single(int64_t val, tzinfo tz1, tzinfo tz2)

pandas/_libs/tslibs/tzconversion.pyx

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ from pandas._libs.tslibs.timezones cimport (
2828
# TODO: cdef scalar version to call from convert_str_to_tsobject
2929
@cython.boundscheck(False)
3030
@cython.wraparound(False)
31-
def tz_localize_to_utc(ndarray[int64_t] vals, object tz, object ambiguous=None,
31+
def tz_localize_to_utc(ndarray[int64_t] vals, tzinfo tz, object ambiguous=None,
3232
object nonexistent=None):
3333
"""
3434
Localize tzinfo-naive i8 to given time zone (using pytz). If
@@ -329,7 +329,7 @@ cdef int64_t tz_convert_utc_to_tzlocal(int64_t utc_val, tzinfo tz, bint* fold=NU
329329
return _tz_convert_tzlocal_utc(utc_val, tz, to_utc=False, fold=fold)
330330

331331

332-
cpdef int64_t tz_convert_single(int64_t val, object tz1, object tz2):
332+
cpdef int64_t tz_convert_single(int64_t val, tzinfo tz1, tzinfo tz2):
333333
"""
334334
Convert the val (in i8) from timezone1 to timezone2
335335
@@ -338,18 +338,15 @@ cpdef int64_t tz_convert_single(int64_t val, object tz1, object tz2):
338338
Parameters
339339
----------
340340
val : int64
341-
tz1 : string / timezone object
342-
tz2 : string / timezone object
341+
tz1 : tzinfo
342+
tz2 : tzinfo
343343
344344
Returns
345345
-------
346346
converted: int64
347347
"""
348348
cdef:
349-
int64_t[:] deltas
350-
Py_ssize_t pos
351-
int64_t v, offset, utc_date
352-
npy_datetimestruct dts
349+
int64_t utc_date
353350
int64_t arr[1]
354351

355352
# See GH#17734 We should always be converting either from UTC or to UTC
@@ -381,17 +378,15 @@ cpdef int64_t tz_convert_single(int64_t val, object tz1, object tz2):
381378
return _tz_convert_dst(arr, tz2, to_utc=False)[0]
382379

383380

384-
@cython.boundscheck(False)
385-
@cython.wraparound(False)
386-
def tz_convert(int64_t[:] vals, object tz1, object tz2):
381+
def tz_convert(int64_t[:] vals, tzinfo tz1, tzinfo tz2):
387382
"""
388383
Convert the values (in i8) from timezone1 to timezone2
389384
390385
Parameters
391386
----------
392387
vals : int64 ndarray
393-
tz1 : string / timezone object
394-
tz2 : string / timezone object
388+
tz1 : tzinfo
389+
tz2 : tzinfo
395390
396391
Returns
397392
-------
@@ -411,15 +406,15 @@ def tz_convert(int64_t[:] vals, object tz1, object tz2):
411406

412407
@cython.boundscheck(False)
413408
@cython.wraparound(False)
414-
cdef int64_t[:] _tz_convert_one_way(int64_t[:] vals, object tz, bint to_utc):
409+
cdef int64_t[:] _tz_convert_one_way(int64_t[:] vals, tzinfo tz, bint to_utc):
415410
"""
416411
Convert the given values (in i8) either to UTC or from UTC.
417412
418413
Parameters
419414
----------
420415
vals : int64 ndarray
421-
tz1 : string / timezone object
422-
to_utc : bint
416+
tz1 : tzinfo
417+
to_utc : bool
423418
424419
Returns
425420
-------
@@ -430,7 +425,7 @@ cdef int64_t[:] _tz_convert_one_way(int64_t[:] vals, object tz, bint to_utc):
430425
Py_ssize_t i, n = len(vals)
431426
int64_t val
432427

433-
if not is_utc(get_timezone(tz)):
428+
if not is_utc(tz):
434429
converted = np.empty(n, dtype=np.int64)
435430
if is_tzlocal(tz):
436431
for i in range(n):

0 commit comments

Comments
 (0)