diff --git a/pandas/_libs/tslibs/tzconversion.pxd b/pandas/_libs/tslibs/tzconversion.pxd index 190205d9c3c44..7f445d7549f45 100644 --- a/pandas/_libs/tslibs/tzconversion.pxd +++ b/pandas/_libs/tslibs/tzconversion.pxd @@ -3,4 +3,4 @@ from numpy cimport int64_t cdef int64_t tz_convert_utc_to_tzlocal(int64_t utc_val, tzinfo tz, bint* fold=*) -cpdef int64_t tz_convert_single(int64_t val, object tz1, object tz2) +cpdef int64_t tz_convert_single(int64_t val, tzinfo tz1, tzinfo tz2) diff --git a/pandas/_libs/tslibs/tzconversion.pyx b/pandas/_libs/tslibs/tzconversion.pyx index 030549f2528ed..ffd076d0608f2 100644 --- a/pandas/_libs/tslibs/tzconversion.pyx +++ b/pandas/_libs/tslibs/tzconversion.pyx @@ -28,7 +28,7 @@ from pandas._libs.tslibs.timezones cimport ( # TODO: cdef scalar version to call from convert_str_to_tsobject @cython.boundscheck(False) @cython.wraparound(False) -def tz_localize_to_utc(ndarray[int64_t] vals, object tz, object ambiguous=None, +def tz_localize_to_utc(ndarray[int64_t] vals, tzinfo tz, object ambiguous=None, object nonexistent=None): """ 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 return _tz_convert_tzlocal_utc(utc_val, tz, to_utc=False, fold=fold) -cpdef int64_t tz_convert_single(int64_t val, object tz1, object tz2): +cpdef int64_t tz_convert_single(int64_t val, tzinfo tz1, tzinfo tz2): """ Convert the val (in i8) from timezone1 to timezone2 @@ -338,18 +338,15 @@ cpdef int64_t tz_convert_single(int64_t val, object tz1, object tz2): Parameters ---------- val : int64 - tz1 : string / timezone object - tz2 : string / timezone object + tz1 : tzinfo + tz2 : tzinfo Returns ------- converted: int64 """ cdef: - int64_t[:] deltas - Py_ssize_t pos - int64_t v, offset, utc_date - npy_datetimestruct dts + int64_t utc_date int64_t arr[1] # 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): return _tz_convert_dst(arr, tz2, to_utc=False)[0] -@cython.boundscheck(False) -@cython.wraparound(False) -def tz_convert(int64_t[:] vals, object tz1, object tz2): +def tz_convert(int64_t[:] vals, tzinfo tz1, tzinfo tz2): """ Convert the values (in i8) from timezone1 to timezone2 Parameters ---------- vals : int64 ndarray - tz1 : string / timezone object - tz2 : string / timezone object + tz1 : tzinfo + tz2 : tzinfo Returns ------- @@ -411,15 +406,15 @@ def tz_convert(int64_t[:] vals, object tz1, object tz2): @cython.boundscheck(False) @cython.wraparound(False) -cdef int64_t[:] _tz_convert_one_way(int64_t[:] vals, object tz, bint to_utc): +cdef int64_t[:] _tz_convert_one_way(int64_t[:] vals, tzinfo tz, bint to_utc): """ Convert the given values (in i8) either to UTC or from UTC. Parameters ---------- vals : int64 ndarray - tz1 : string / timezone object - to_utc : bint + tz1 : tzinfo + to_utc : bool Returns ------- @@ -430,7 +425,7 @@ cdef int64_t[:] _tz_convert_one_way(int64_t[:] vals, object tz, bint to_utc): Py_ssize_t i, n = len(vals) int64_t val - if not is_utc(get_timezone(tz)): + if not is_utc(tz): converted = np.empty(n, dtype=np.int64) if is_tzlocal(tz): for i in range(n):