Skip to content

Commit 7d1b37b

Browse files
committed
Fix test, import optional pytz in conftest
1 parent 19d424b commit 7d1b37b

File tree

2 files changed

+23
-27
lines changed

2 files changed

+23
-27
lines changed

pandas/conftest.py

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@
3232
import gc
3333
import operator
3434
import os
35-
from typing import TYPE_CHECKING
35+
from typing import (
36+
TYPE_CHECKING,
37+
Any,
38+
)
3639
import uuid
3740

3841
from dateutil.tz import (
@@ -43,11 +46,8 @@
4346
from hypothesis import strategies as st
4447
import numpy as np
4548
import pytest
46-
from pytz import (
47-
FixedOffset,
48-
utc,
49-
)
5049

50+
from pandas.compat._optional import import_optional_dependency
5151
import pandas.util._test_decorators as td
5252

5353
from pandas.core.dtypes.dtypes import (
@@ -93,12 +93,7 @@
9393
del pa
9494
has_pyarrow = True
9595

96-
import zoneinfo
97-
98-
try:
99-
zoneinfo.ZoneInfo("UTC")
100-
except zoneinfo.ZoneInfoNotFoundError:
101-
zoneinfo = None # type: ignore[assignment]
96+
pytz = import_optional_dependency("pytz", errors="ignore")
10297

10398

10499
# ----------------------------------------------------------------
@@ -1196,19 +1191,19 @@ def deco(*args):
11961191
"UTC-02:15",
11971192
tzutc(),
11981193
tzlocal(),
1199-
FixedOffset(300),
1200-
FixedOffset(0),
1201-
FixedOffset(-300),
12021194
timezone.utc,
12031195
timezone(timedelta(hours=1)),
12041196
timezone(timedelta(hours=-1), name="foo"),
12051197
]
1206-
if zoneinfo is not None:
1198+
if pytz is not None:
12071199
TIMEZONES.extend(
1208-
[
1209-
zoneinfo.ZoneInfo("US/Pacific"), # type: ignore[list-item]
1210-
zoneinfo.ZoneInfo("UTC"), # type: ignore[list-item]
1211-
]
1200+
(
1201+
pytz.FixedOffset(300),
1202+
pytz.FixedOffset(0),
1203+
pytz.FixedOffset(-300),
1204+
pytz.timezone("US/Pacific"),
1205+
pytz.timezone("UTC"),
1206+
)
12121207
)
12131208
TIMEZONE_IDS = [repr(i) for i in TIMEZONES]
12141209

@@ -1231,9 +1226,10 @@ def tz_aware_fixture(request):
12311226
return request.param
12321227

12331228

1234-
_UTCS = ["utc", "dateutil/UTC", utc, tzutc(), timezone.utc]
1235-
if zoneinfo is not None:
1236-
_UTCS.append(zoneinfo.ZoneInfo("UTC"))
1229+
_UTCS = ["utc", "dateutil/UTC", tzutc(), timezone.utc]
1230+
1231+
if pytz is not None:
1232+
_UTCS.append(pytz.utc)
12371233

12381234

12391235
@pytest.fixture(params=_UTCS)
@@ -1995,12 +1991,12 @@ def using_infer_string() -> bool:
19951991
return pd.options.future.infer_string is True
19961992

19971993

1998-
warsaws = ["Europe/Warsaw", "dateutil/Europe/Warsaw"]
1999-
if zoneinfo is not None:
2000-
warsaws.append(zoneinfo.ZoneInfo("Europe/Warsaw")) # type: ignore[arg-type]
1994+
_warsaws: list[Any] = ["Europe/Warsaw", "dateutil/Europe/Warsaw"]
1995+
if pytz is not None:
1996+
_warsaws.append(pytz.timezone("Europe/Warsaw")) # type: ignore[arg-type]
20011997

20021998

2003-
@pytest.fixture(params=warsaws)
1999+
@pytest.fixture(params=_warsaws)
20042000
def warsaw(request) -> str:
20052001
"""
20062002
tzinfo for Europe/Warsaw using pytz, dateutil, or zoneinfo.

pandas/tests/test_downstream.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def test_missing_required_dependency():
218218
subprocess.check_output(call, stderr=subprocess.STDOUT)
219219

220220
output = exc.value.stdout.decode()
221-
for name in ["numpy", "pytz", "dateutil"]:
221+
for name in ["numpy", "dateutil"]:
222222
assert name in output
223223

224224

0 commit comments

Comments
 (0)