diff --git a/pandas/_libs/tslib.pyx b/pandas/_libs/tslib.pyx index f6034a1347f90..aad5be7ad99a8 100644 --- a/pandas/_libs/tslib.pyx +++ b/pandas/_libs/tslib.pyx @@ -44,8 +44,12 @@ from pandas._libs.tslibs.np_datetime import OutOfBoundsDatetime from pandas._libs.tslibs.parsing import parse_datetime_string from pandas._libs.tslibs.timedeltas cimport cast_from_unit -from pandas._libs.tslibs.timezones cimport is_utc, is_tzlocal, get_dst_info -from pandas._libs.tslibs.timezones import UTC +from pandas._libs.tslibs.timezones cimport ( + get_dst_info, + is_utc, + is_tzlocal, + utc_pytz as UTC, +) from pandas._libs.tslibs.conversion cimport ( _TSObject, convert_datetime_to_tsobject, get_datetime64_nanos) diff --git a/pandas/_libs/tslibs/conversion.pyx b/pandas/_libs/tslibs/conversion.pyx index b8544e2a9f39e..199a41a6a0cf3 100644 --- a/pandas/_libs/tslibs/conversion.pyx +++ b/pandas/_libs/tslibs/conversion.pyx @@ -42,8 +42,9 @@ from pandas._libs.tslibs.nattype cimport ( from pandas._libs.tslibs.tzconversion import tz_localize_to_utc from pandas._libs.tslibs.tzconversion cimport ( - _tz_convert_tzlocal_utc, _tz_convert_tzlocal_fromutc, - tz_convert_single + tz_convert_utc_to_tzlocal, + _tz_convert_tzlocal_fromutc, + tz_convert_single, ) # ---------------------------------------------------------------------- @@ -706,8 +707,7 @@ def normalize_i8_timestamps(int64_t[:] stamps, object tz): result : int64 ndarray of converted of normalized nanosecond timestamps """ cdef: - Py_ssize_t n = len(stamps) - int64_t[:] result = np.empty(n, dtype=np.int64) + int64_t[:] result result = _normalize_local(stamps, tz) @@ -746,7 +746,7 @@ cdef int64_t[:] _normalize_local(const int64_t[:] stamps, tzinfo tz): if stamps[i] == NPY_NAT: result[i] = NPY_NAT continue - local_val = _tz_convert_tzlocal_utc(stamps[i], tz, to_utc=False) + local_val = tz_convert_utc_to_tzlocal(stamps[i], tz) dt64_to_dtstruct(local_val, &dts) result[i] = _normalized_stamp(&dts) else: @@ -827,7 +827,7 @@ def is_date_array_normalized(const int64_t[:] stamps, object tz=None): return False elif is_tzlocal(tz): for i in range(n): - local_val = _tz_convert_tzlocal_utc(stamps[i], tz, to_utc=False) + local_val = tz_convert_utc_to_tzlocal(stamps[i], tz) dt64_to_dtstruct(local_val, &dts) if (dts.hour + dts.min + dts.sec + dts.us) > 0: return False diff --git a/pandas/_libs/tslibs/timezones.pxd b/pandas/_libs/tslibs/timezones.pxd index 2f2a60fe6edf5..14c0523787422 100644 --- a/pandas/_libs/tslibs/timezones.pxd +++ b/pandas/_libs/tslibs/timezones.pxd @@ -6,13 +6,12 @@ cpdef bint is_utc(object tz) cdef bint is_tzlocal(object tz) cdef bint treat_tz_as_pytz(object tz) -cdef bint treat_tz_as_dateutil(object tz) cpdef bint tz_compare(object start, object end) cpdef object get_timezone(object tz) cpdef object maybe_get_tz(object tz) cdef get_utcoffset(tzinfo tz, obj) -cdef bint is_fixed_offset(object tz) +cdef bint is_fixed_offset(tzinfo tz) cdef object get_dst_info(object tz) diff --git a/pandas/_libs/tslibs/timezones.pyx b/pandas/_libs/tslibs/timezones.pyx index 1edd5095b8749..7fbb50fcbfd41 100644 --- a/pandas/_libs/tslibs/timezones.pyx +++ b/pandas/_libs/tslibs/timezones.pyx @@ -3,14 +3,13 @@ from datetime import timezone # dateutil compat from dateutil.tz import ( + gettz as dateutil_gettz, tzfile as _dateutil_tzfile, tzlocal as _dateutil_tzlocal, tzutc as _dateutil_tzutc, ) -from dateutil.tz import gettz as dateutil_gettz - from pytz.tzinfo import BaseTzInfo as _pytz_BaseTzInfo import pytz UTC = pytz.utc @@ -161,7 +160,7 @@ cdef get_utcoffset(tzinfo tz, obj): return tz.utcoffset(obj) -cdef inline bint is_fixed_offset(object tz): +cdef inline bint is_fixed_offset(tzinfo tz): if treat_tz_as_dateutil(tz): if len(tz._trans_idx) == 0 and len(tz._trans_list) == 0: return 1 @@ -178,7 +177,7 @@ cdef inline bint is_fixed_offset(object tz): return 1 -cdef object get_utc_trans_times_from_dateutil_tz(object tz): +cdef object _get_utc_trans_times_from_dateutil_tz(tzinfo tz): """ Transition times in dateutil timezones are stored in local non-dst time. This code converts them to UTC. It's the reverse of the code @@ -240,7 +239,7 @@ cdef object get_dst_info(object tz): elif treat_tz_as_dateutil(tz): if len(tz._trans_list): # get utc trans times - trans_list = get_utc_trans_times_from_dateutil_tz(tz) + trans_list = _get_utc_trans_times_from_dateutil_tz(tz) trans = np.hstack([ np.array([0], dtype='M8[s]'), # place holder for 1st item np.array(trans_list, dtype='M8[s]')]).astype( diff --git a/pandas/_libs/tslibs/tzconversion.pxd b/pandas/_libs/tslibs/tzconversion.pxd index c1dd88e5b2313..b91117e3e2a67 100644 --- a/pandas/_libs/tslibs/tzconversion.pxd +++ b/pandas/_libs/tslibs/tzconversion.pxd @@ -3,6 +3,5 @@ from numpy cimport int64_t cdef int64_t tz_convert_utc_to_tzlocal(int64_t utc_val, tzinfo tz) -cdef int64_t _tz_convert_tzlocal_utc(int64_t val, tzinfo tz, bint to_utc=*) cdef int64_t _tz_convert_tzlocal_fromutc(int64_t val, tzinfo tz, bint *fold) cpdef int64_t tz_convert_single(int64_t val, object tz1, object tz2) diff --git a/pandas/_libs/tslibs/util.pxd b/pandas/_libs/tslibs/util.pxd index eb535a994e538..90e0677fb0063 100644 --- a/pandas/_libs/tslibs/util.pxd +++ b/pandas/_libs/tslibs/util.pxd @@ -23,8 +23,6 @@ cdef extern from "Python.h": # thus they cannot be declared 'nogil'. Also PyUnicode_AsUTF8AndSize() can # potentially allocate memory inside in unlikely case of when underlying # unicode object was stored as non-utf8 and utf8 wasn't requested before. - bint PyBytes_AsStringAndSize(object obj, char** buf, - Py_ssize_t* length) except -1 const char* PyUnicode_AsUTF8AndSize(object obj, Py_ssize_t* length) except NULL