Skip to content

Commit 4d65e82

Browse files
lithomas1YYYasin19
authored andcommitted
DEPS/TST: tzdata is optional, not required (pandas-dev#47467)
1 parent 1950924 commit 4d65e82

11 files changed

+44
-1
lines changed

ci/deps/actions-310.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ dependencies:
4747
- scipy
4848
- sqlalchemy
4949
- tabulate
50+
- tzdata>=2022a
5051
- xarray
5152
- xlrd
5253
- xlsxwriter

ci/deps/actions-38-minimum_versions.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ dependencies:
4949
- scipy=1.7.1
5050
- sqlalchemy=1.4.16
5151
- tabulate=0.8.9
52+
- tzdata=2022a
5253
- xarray=0.19.0
5354
- xlrd=2.0.1
5455
- xlsxwriter=1.4.3

ci/deps/actions-39.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ dependencies:
4747
- scipy
4848
- sqlalchemy
4949
- tabulate
50+
- tzdata>=2022a
5051
- xarray
5152
- xlrd
5253
- xlsxwriter

doc/source/getting_started/install.rst

+17
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,23 @@ For example, :func:`pandas.read_hdf` requires the ``pytables`` package, while
270270
optional dependency is not installed, pandas will raise an ``ImportError`` when
271271
the method requiring that dependency is called.
272272

273+
Timezones
274+
^^^^^^^^^
275+
276+
========================= ========================= =============================================================
277+
Dependency Minimum Version Notes
278+
========================= ========================= =============================================================
279+
tzdata 2022.1(pypi)/ Allows the use of ``zoneinfo`` timezones with pandas.
280+
2022a(for system tzdata) **Note**: You only need to install the pypi package if your
281+
system does not already provide the IANA tz database.
282+
However, the minimum tzdata version still applies, even if it
283+
is not enforced through an error.
284+
285+
If you would like to keep your system tzdata version updated,
286+
it is recommended to use the ``tzdata`` package from
287+
conda-forge.
288+
========================= ========================= =============================================================
289+
273290
Visualization
274291
^^^^^^^^^^^^^
275292

environment.yml

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ dependencies:
4848
- scipy
4949
- sqlalchemy
5050
- tabulate
51+
- tzdata>=2022a
5152
- xarray
5253
- xlrd
5354
- xlsxwriter

pandas/_libs/tslibs/timezones.pyx

+5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ from datetime import (
33
timezone,
44
)
55

6+
from pandas.compat._optional import import_optional_dependency
7+
68
try:
79
# py39+
810
import zoneinfo
@@ -67,6 +69,9 @@ cdef inline bint is_utc_zoneinfo(tzinfo tz):
6769
utc_zoneinfo = ZoneInfo("UTC")
6870
except zoneinfo.ZoneInfoNotFoundError:
6971
return False
72+
# Warn if tzdata is too old, even if there is a system tzdata to alert
73+
# users about the mismatch between local/system tzdata
74+
import_optional_dependency("tzdata", errors="warn", min_version="2022.1")
7075

7176
return tz is utc_zoneinfo
7277

pandas/compat/_optional.py

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"xlwt": "1.3.0",
4545
"xlsxwriter": "1.4.3",
4646
"zstandard": "0.15.2",
47+
"tzdata": "2022.1",
4748
}
4849

4950
# A mapping from import name to package name (on PyPI) for packages where

pandas/conftest.py

+8
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@
8383
# Import "zoneinfo" could not be resolved (reportMissingImports)
8484
import zoneinfo # type: ignore[no-redef]
8585

86+
# Although zoneinfo can be imported in Py39, it is effectively
87+
# "not available" without tzdata/IANA tz data.
88+
# We will set zoneinfo to not found in this case
89+
try:
90+
zoneinfo.ZoneInfo("UTC") # type: ignore[attr-defined]
91+
except zoneinfo.ZoneInfoNotFoundError: # type: ignore[attr-defined]
92+
zoneinfo = None
93+
8694
# Until https://github.com/numpy/numpy/issues/19078 is sorted out, just suppress
8795
suppress_npdev_promotion_warning = pytest.mark.filterwarnings(
8896
"ignore:Promotion of numbers and bools:FutureWarning"

requirements-dev.txt

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ s3fs
3939
scipy
4040
sqlalchemy
4141
tabulate
42+
tzdata>=2022.1
4243
xarray
4344
xlrd
4445
xlsxwriter

scripts/generate_pip_deps_from_conda.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import yaml
2222

2323
EXCLUDE = {"python", "c-compiler", "cxx-compiler"}
24+
REMAP_VERSION = {"tzdata": "2022.1"}
2425
RENAME = {"pytables": "tables", "geopandas-base": "geopandas", "pytorch": "torch"}
2526

2627

@@ -41,7 +42,8 @@ def conda_package_to_pip(package: str):
4142
pkg, version = package.split(compare)
4243
if pkg in EXCLUDE:
4344
return
44-
45+
if pkg in REMAP_VERSION:
46+
return "".join((pkg, compare, REMAP_VERSION[pkg]))
4547
if pkg in RENAME:
4648
return "".join((RENAME[pkg], compare, version))
4749

scripts/validate_min_versions_in_sync.py

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
pathlib.Path("ci/deps").absolute().glob("actions-*-minimum_versions.yaml")
2222
)
2323
CODE_PATH = pathlib.Path("pandas/compat/_optional.py").resolve()
24+
EXCLUDE_DEPS = {"tzdata"}
2425
# pandas package is not available
2526
# in pre-commit environment
2627
sys.path.append("pandas/compat")
@@ -34,6 +35,8 @@
3435
def get_versions_from_code() -> dict[str, str]:
3536
install_map = _optional.INSTALL_MAPPING
3637
versions = _optional.VERSIONS
38+
for item in EXCLUDE_DEPS:
39+
versions.pop(item)
3740
return {
3841
install_map.get(k, k).casefold(): v
3942
for k, v in versions.items()
@@ -55,6 +58,8 @@ def get_versions_from_ci(content: list[str]) -> tuple[dict[str, str], dict[str,
5558
elif seen_required and line.strip():
5659
package, version = line.strip().split("=")
5760
package = package[2:]
61+
if package in EXCLUDE_DEPS:
62+
continue
5863
if not seen_optional:
5964
required_deps[package] = version
6065
else:

0 commit comments

Comments
 (0)