Skip to content
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

DEPS/TST: tzdata is optional, not required #47467

Merged
merged 17 commits into from
Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from 15 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
1 change: 1 addition & 0 deletions ci/deps/actions-310.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ dependencies:
- scipy
- sqlalchemy
- tabulate
- tzdata>=2022a
- xarray
- xlrd
- xlsxwriter
Expand Down
1 change: 1 addition & 0 deletions ci/deps/actions-38-minimum_versions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ dependencies:
- scipy=1.7.1
- sqlalchemy=1.4.16
- tabulate=0.8.9
- tzdata=2022a
- xarray=0.19.0
- xlrd=2.0.1
- xlsxwriter=1.4.3
Expand Down
1 change: 1 addition & 0 deletions ci/deps/actions-39.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ dependencies:
- scipy
- sqlalchemy
- tabulate
- tzdata>=2022a
- xarray
- xlrd
- xlsxwriter
Expand Down
13 changes: 13 additions & 0 deletions doc/source/getting_started/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,19 @@ For example, :func:`pandas.read_hdf` requires the ``pytables`` package, while
optional dependency is not installed, pandas will raise an ``ImportError`` when
the method requiring that dependency is called.

Timezones
^^^^^^^^^

========================= ========================= =============================================================
Dependency Minimum Version Notes
========================= ========================= =============================================================
tzdata 2022.1(pypi)/ Allows the use of ``zoneinfo`` timezones with pandas.
2022a(for system tzdata) **Note**: You only need to install the pypi package, if your
Copy link
Member

Choose a reason for hiding this comment

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

Looks like the 2022a is a conda forge package?
https://anaconda.org/conda-forge/tzdata
https://github.com/eggert/tz

Which is a different project from tzdata (2022.1).
https://pypi.org/project/tzdata/#history
https://github.com/python/tzdata

I'm not sure it's a good idea to recommend 2 differently maintained packages here. Can we just recommend the pypi one since it's the once recommended in the official docs https://docs.python.org/3/library/zoneinfo.html#data-sources?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we'd still want to state a min version for system tzdata for consistency. 2022a is also the version of the actual IANA tz db(it's python's tzdata versioning scheme that's different).

Copy link
Member

Choose a reason for hiding this comment

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

Ah okay sounds reasonable then. Might be good then to mention that the system tzdata can be updated by installing the conda forge package?

system does not already provide the IANA tz database.
However, the minimum tzdata version still applies, even if it
is not enforced through an error.
========================= ========================= =============================================================

Visualization
^^^^^^^^^^^^^

Expand Down
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ dependencies:
- scipy
- sqlalchemy
- tabulate
- tzdata>=2022a
- xarray
- xlrd
- xlsxwriter
Expand Down
5 changes: 5 additions & 0 deletions pandas/_libs/tslibs/timezones.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ from datetime import (
timezone,
)

from pandas.compat._optional import import_optional_dependency

try:
# py39+
import zoneinfo
Expand Down Expand Up @@ -67,6 +69,9 @@ cdef inline bint is_utc_zoneinfo(tzinfo tz):
utc_zoneinfo = ZoneInfo("UTC")
except zoneinfo.ZoneInfoNotFoundError:
return False
# Warn if tzdata is too old, even if there is a system tzdata to alert
# users about the mismatch between local/system tzdata
import_optional_dependency("tzdata", errors="warn", min_version="2022.1")

return tz is utc_zoneinfo

Expand Down
1 change: 1 addition & 0 deletions pandas/compat/_optional.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"xlwt": "1.3.0",
"xlsxwriter": "1.4.3",
"zstandard": "0.15.2",
"tzdata": "2022.1",
}

# A mapping from import name to package name (on PyPI) for packages where
Expand Down
8 changes: 8 additions & 0 deletions pandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@
# Import "zoneinfo" could not be resolved (reportMissingImports)
import zoneinfo # type: ignore[no-redef]

# Although zoneinfo can be imported in Py39, it is effectively
# "not available" without tzdata/IANA tz data.
# We will set zoneinfo to not found in this case
try:
zoneinfo.ZoneInfo("UTC") # type: ignore[attr-defined]
except zoneinfo.ZoneInfoNotFoundError: # type: ignore[attr-defined]
zoneinfo = None

# Until https://github.com/numpy/numpy/issues/19078 is sorted out, just suppress
suppress_npdev_promotion_warning = pytest.mark.filterwarnings(
"ignore:Promotion of numbers and bools:FutureWarning"
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ s3fs
scipy
sqlalchemy
tabulate
tzdata>=2022.1
xarray
xlrd
xlsxwriter
Expand Down
4 changes: 3 additions & 1 deletion scripts/generate_pip_deps_from_conda.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import yaml

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


Expand All @@ -41,7 +42,8 @@ def conda_package_to_pip(package: str):
pkg, version = package.split(compare)
if pkg in EXCLUDE:
return

if pkg in REMAP_VERSION:
return "".join((pkg, compare, REMAP_VERSION[pkg]))
if pkg in RENAME:
return "".join((RENAME[pkg], compare, version))

Expand Down
5 changes: 5 additions & 0 deletions scripts/validate_min_versions_in_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
pathlib.Path("ci/deps").absolute().glob("actions-*-minimum_versions.yaml")
)
CODE_PATH = pathlib.Path("pandas/compat/_optional.py").resolve()
EXCLUDE_DEPS = {"tzdata"}
# pandas package is not available
# in pre-commit environment
sys.path.append("pandas/compat")
Expand All @@ -34,6 +35,8 @@
def get_versions_from_code() -> dict[str, str]:
install_map = _optional.INSTALL_MAPPING
versions = _optional.VERSIONS
for item in EXCLUDE_DEPS:
versions.pop(item)
return {
install_map.get(k, k).casefold(): v
for k, v in versions.items()
Expand All @@ -55,6 +58,8 @@ def get_versions_from_ci(content: list[str]) -> tuple[dict[str, str], dict[str,
elif seen_required and line.strip():
package, version = line.strip().split("=")
package = package[2:]
if package in EXCLUDE_DEPS:
continue
if not seen_optional:
required_deps[package] = version
else:
Expand Down