32
32
import gc
33
33
import operator
34
34
import os
35
- from typing import TYPE_CHECKING
35
+ from typing import (
36
+ TYPE_CHECKING ,
37
+ Any ,
38
+ )
36
39
import uuid
37
40
38
41
from dateutil .tz import (
43
46
from hypothesis import strategies as st
44
47
import numpy as np
45
48
import pytest
46
- from pytz import (
47
- FixedOffset ,
48
- utc ,
49
- )
50
49
50
+ from pandas .compat ._optional import import_optional_dependency
51
51
import pandas .util ._test_decorators as td
52
52
53
53
from pandas .core .dtypes .dtypes import (
93
93
del pa
94
94
has_pyarrow = True
95
95
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" )
102
97
103
98
104
99
# ----------------------------------------------------------------
@@ -1196,19 +1191,19 @@ def deco(*args):
1196
1191
"UTC-02:15" ,
1197
1192
tzutc (),
1198
1193
tzlocal (),
1199
- FixedOffset (300 ),
1200
- FixedOffset (0 ),
1201
- FixedOffset (- 300 ),
1202
1194
timezone .utc ,
1203
1195
timezone (timedelta (hours = 1 )),
1204
1196
timezone (timedelta (hours = - 1 ), name = "foo" ),
1205
1197
]
1206
- if zoneinfo is not None :
1198
+ if pytz is not None :
1207
1199
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
+ )
1212
1207
)
1213
1208
TIMEZONE_IDS = [repr (i ) for i in TIMEZONES ]
1214
1209
@@ -1231,9 +1226,10 @@ def tz_aware_fixture(request):
1231
1226
return request .param
1232
1227
1233
1228
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 )
1237
1233
1238
1234
1239
1235
@pytest .fixture (params = _UTCS )
@@ -1995,12 +1991,12 @@ def using_infer_string() -> bool:
1995
1991
return pd .options .future .infer_string is True
1996
1992
1997
1993
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]
2001
1997
2002
1998
2003
- @pytest .fixture (params = warsaws )
1999
+ @pytest .fixture (params = _warsaws )
2004
2000
def warsaw (request ) -> str :
2005
2001
"""
2006
2002
tzinfo for Europe/Warsaw using pytz, dateutil, or zoneinfo.
0 commit comments