Skip to content

BUG: is_utc(dateutil_utc) #39276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 21, 2021
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 doc/source/whatsnew/v1.3.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ Timedelta
Timezones
^^^^^^^^^
- Bug in different ``tzinfo`` objects representing UTC not being treated as equivalent (:issue:`39216`)
-
- Bug in ``dateutil.tz.gettz("UTC")`` not being recognized as equivalent to other UTC-representing tzinfos (:issue:`39276`)
-

Numeric
Expand Down
9 changes: 8 additions & 1 deletion pandas/_libs/tslibs/timezones.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,18 @@ from pandas._libs.tslibs.util cimport get_nat, is_integer_object
cdef int64_t NPY_NAT = get_nat()
cdef tzinfo utc_stdlib = timezone.utc
cdef tzinfo utc_pytz = UTC
cdef tzinfo utc_dateutil_str = dateutil_gettz("UTC") # NB: *not* the same as tzutc()


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

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


cdef inline bint is_tzlocal(tzinfo tz):
Expand Down
3 changes: 3 additions & 0 deletions pandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,9 @@ def utc_fixture(request):
return request.param


utc_fixture2 = utc_fixture
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this 2nd fixture here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, wont be needed until both this and the tz_compare PR are in

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added the extra test below since the other PR got merged



# ----------------------------------------------------------------
# Dtypes
# ----------------------------------------------------------------
Expand Down
11 changes: 11 additions & 0 deletions pandas/tests/tslibs/test_timezones.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
from pandas import Timestamp


def test_is_utc(utc_fixture):
tz = timezones.maybe_get_tz(utc_fixture)
assert timezones.is_utc(tz)


@pytest.mark.parametrize("tz_name", list(pytz.common_timezones))
def test_cache_keys_are_distinct_for_pytz_vs_dateutil(tz_name):
if tz_name == "UTC":
Expand Down Expand Up @@ -56,6 +61,12 @@ def test_tzlocal_is_not_utc():
assert not timezones.tz_compare(tz, dateutil.tz.tzutc())


def test_tz_compare_utc(utc_fixture, utc_fixture2):
tz = timezones.maybe_get_tz(utc_fixture)
tz2 = timezones.maybe_get_tz(utc_fixture2)
assert timezones.tz_compare(tz, tz2)


@pytest.fixture(
params=[
(pytz.timezone("US/Eastern"), lambda tz, x: tz.localize(x)),
Expand Down