Skip to content

Commit 830b408

Browse files
authored
BUG: is_utc(dateutil_utc) (#39276)
1 parent ac2fd4e commit 830b408

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

doc/source/whatsnew/v1.3.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ Timedelta
247247
Timezones
248248
^^^^^^^^^
249249
- Bug in different ``tzinfo`` objects representing UTC not being treated as equivalent (:issue:`39216`)
250-
-
250+
- Bug in ``dateutil.tz.gettz("UTC")`` not being recognized as equivalent to other UTC-representing tzinfos (:issue:`39276`)
251251
-
252252

253253
Numeric

pandas/_libs/tslibs/timezones.pyx

+8-1
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,18 @@ from pandas._libs.tslibs.util cimport get_nat, is_integer_object
3030
cdef int64_t NPY_NAT = get_nat()
3131
cdef tzinfo utc_stdlib = timezone.utc
3232
cdef tzinfo utc_pytz = UTC
33+
cdef tzinfo utc_dateutil_str = dateutil_gettz("UTC") # NB: *not* the same as tzutc()
34+
3335

3436
# ----------------------------------------------------------------------
3537

3638
cpdef inline bint is_utc(tzinfo tz):
37-
return tz is utc_pytz or tz is utc_stdlib or isinstance(tz, _dateutil_tzutc)
39+
return (
40+
tz is utc_pytz
41+
or tz is utc_stdlib
42+
or isinstance(tz, _dateutil_tzutc)
43+
or tz is utc_dateutil_str
44+
)
3845

3946

4047
cdef inline bint is_tzlocal(tzinfo tz):

pandas/conftest.py

+3
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,9 @@ def utc_fixture(request):
10411041
return request.param
10421042

10431043

1044+
utc_fixture2 = utc_fixture
1045+
1046+
10441047
# ----------------------------------------------------------------
10451048
# Dtypes
10461049
# ----------------------------------------------------------------

pandas/tests/tslibs/test_timezones.py

+11
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
from pandas import Timestamp
1010

1111

12+
def test_is_utc(utc_fixture):
13+
tz = timezones.maybe_get_tz(utc_fixture)
14+
assert timezones.is_utc(tz)
15+
16+
1217
@pytest.mark.parametrize("tz_name", list(pytz.common_timezones))
1318
def test_cache_keys_are_distinct_for_pytz_vs_dateutil(tz_name):
1419
if tz_name == "UTC":
@@ -56,6 +61,12 @@ def test_tzlocal_is_not_utc():
5661
assert not timezones.tz_compare(tz, dateutil.tz.tzutc())
5762

5863

64+
def test_tz_compare_utc(utc_fixture, utc_fixture2):
65+
tz = timezones.maybe_get_tz(utc_fixture)
66+
tz2 = timezones.maybe_get_tz(utc_fixture2)
67+
assert timezones.tz_compare(tz, tz2)
68+
69+
5970
@pytest.fixture(
6071
params=[
6172
(pytz.timezone("US/Eastern"), lambda tz, x: tz.localize(x)),

0 commit comments

Comments
 (0)