Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/timestamps.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@ class Timestamp(_Timestamp):
"Timestamp from components."
)

if tz is not None and treat_tz_as_pytz(tz):
if tz is not None and PyTZInfo_Check(tz) and treat_tz_as_pytz(tz):
raise ValueError(
"pytz timezones do not support fold. Please use dateutil "
"timezones."
Expand Down
6 changes: 3 additions & 3 deletions pandas/_libs/tslibs/timezones.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ from cpython.datetime cimport tzinfo

cdef tzinfo utc_pytz

cpdef bint is_utc(object tz)
cdef bint is_tzlocal(object tz)
cpdef bint is_utc(tzinfo tz)
cdef bint is_tzlocal(tzinfo tz)

cdef bint treat_tz_as_pytz(object tz)
cdef bint treat_tz_as_pytz(tzinfo tz)

cpdef bint tz_compare(object start, object end)
cpdef object get_timezone(object tz)
Expand Down
17 changes: 10 additions & 7 deletions pandas/_libs/tslibs/timezones.pyx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from cpython.datetime cimport tzinfo
from datetime import timezone
from cpython.datetime cimport tzinfo, PyTZInfo_Check, PyDateTime_IMPORT
PyDateTime_IMPORT

# dateutil compat
from dateutil.tz import (
Expand Down Expand Up @@ -29,20 +30,20 @@ cdef tzinfo utc_pytz = UTC

# ----------------------------------------------------------------------

cpdef inline bint is_utc(object tz):
cpdef inline bint is_utc(tzinfo tz):
return tz is utc_pytz or tz is utc_stdlib or isinstance(tz, _dateutil_tzutc)


cdef inline bint is_tzlocal(object tz):
cdef inline bint is_tzlocal(tzinfo tz):
return isinstance(tz, _dateutil_tzlocal)


cdef inline bint treat_tz_as_pytz(object tz):
cdef inline bint treat_tz_as_pytz(tzinfo tz):
return (hasattr(tz, '_utc_transition_times') and
hasattr(tz, '_transition_info'))


cdef inline bint treat_tz_as_dateutil(object tz):
cdef inline bint treat_tz_as_dateutil(tzinfo tz):
return hasattr(tz, '_trans_list') and hasattr(tz, '_trans_idx')


Expand All @@ -59,7 +60,9 @@ cpdef inline object get_timezone(object tz):
the tz name. It needs to be a string so that we can serialize it with
UJSON/pytables. maybe_get_tz (below) is the inverse of this process.
"""
if is_utc(tz):
if not PyTZInfo_Check(tz):
return tz
elif is_utc(tz):
return tz
else:
if treat_tz_as_dateutil(tz):
Expand Down Expand Up @@ -325,7 +328,7 @@ cpdef bint tz_compare(object start, object end):
return get_timezone(start) == get_timezone(end)


def tz_standardize(tz: object):
def tz_standardize(tz: tzinfo):
"""
If the passed tz is a pytz timezone object, "normalize" it to the a
consistent version
Expand Down