From 2939c10e07d825a247382e47f615d84d7a2f80f4 Mon Sep 17 00:00:00 2001 From: Thomas Li <47963215+lithomas1@users.noreply.github.com> Date: Wed, 22 Jun 2022 10:55:59 -0700 Subject: [PATCH 01/11] DEPS/TST: tzdata is optional, not required --- pandas/conftest.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pandas/conftest.py b/pandas/conftest.py index dfe8c5f1778d3..c69359ec4fa61 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -78,6 +78,13 @@ if pd.compat.PY39: # 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: + utc_zoneinfo = ZoneInfo("UTC") + except ZoneInfoNotFoundError: + zoneinfo = None # Until https://github.com/numpy/numpy/issues/19078 is sorted out, just suppress suppress_npdev_promotion_warning = pytest.mark.filterwarnings( From d4642a9b4b28aa72f99cf872721599d723814868 Mon Sep 17 00:00:00 2001 From: Thomas Li <47963215+lithomas1@users.noreply.github.com> Date: Wed, 22 Jun 2022 11:14:22 -0700 Subject: [PATCH 02/11] Fix name & formatting --- pandas/conftest.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index c69359ec4fa61..90830af7d0f01 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -78,12 +78,13 @@ if pd.compat.PY39: # 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: utc_zoneinfo = ZoneInfo("UTC") - except ZoneInfoNotFoundError: + except zoneinfo.ZoneInfoNotFoundError: zoneinfo = None # Until https://github.com/numpy/numpy/issues/19078 is sorted out, just suppress From 9a75b8546b91cdc8d5cd79fbfa809489f94d6423 Mon Sep 17 00:00:00 2001 From: Thomas Li <47963215+lithomas1@users.noreply.github.com> Date: Wed, 22 Jun 2022 11:22:38 -0700 Subject: [PATCH 03/11] another one --- pandas/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index 90830af7d0f01..4253e15f0bd5c 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -83,7 +83,7 @@ # "not available" without tzdata/IANA tz data. # We will set zoneinfo to not found in this case try: - utc_zoneinfo = ZoneInfo("UTC") + utc_zoneinfo = zoneinfo.ZoneInfo("UTC") except zoneinfo.ZoneInfoNotFoundError: zoneinfo = None From bfff26869e1d6a241dcd4e1bdedcc81be92892ef Mon Sep 17 00:00:00 2001 From: Thomas Li <47963215+lithomas1@users.noreply.github.com> Date: Fri, 29 Jul 2022 08:07:48 -0700 Subject: [PATCH 04/11] Update pandas/conftest.py Co-authored-by: Matthew Roeschke --- pandas/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index 4253e15f0bd5c..878b3b4059a16 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -83,7 +83,7 @@ # "not available" without tzdata/IANA tz data. # We will set zoneinfo to not found in this case try: - utc_zoneinfo = zoneinfo.ZoneInfo("UTC") + zoneinfo.ZoneInfo("UTC") except zoneinfo.ZoneInfoNotFoundError: zoneinfo = None From 3c94243b626b003868b98f6058634c946be679ca Mon Sep 17 00:00:00 2001 From: Thomas Li <47963215+lithomas1@users.noreply.github.com> Date: Fri, 29 Jul 2022 08:17:16 -0700 Subject: [PATCH 05/11] make tzdata an optional dependency --- ci/deps/actions-310.yaml | 1 + ci/deps/actions-38-minimum_versions.yaml | 1 + ci/deps/actions-39.yaml | 1 + doc/source/getting_started/install.rst | 9 +++++++++ environment.yml | 1 + pandas/_libs/tslibs/timezones.pyx | 3 +++ pandas/compat/_optional.py | 1 + requirements-dev.txt | 1 + 8 files changed, 18 insertions(+) diff --git a/ci/deps/actions-310.yaml b/ci/deps/actions-310.yaml index 73700c0da0d47..192c947dc668e 100644 --- a/ci/deps/actions-310.yaml +++ b/ci/deps/actions-310.yaml @@ -47,6 +47,7 @@ dependencies: - scipy - sqlalchemy - tabulate + - tzdata>=2022.1 - xarray - xlrd - xlsxwriter diff --git a/ci/deps/actions-38-minimum_versions.yaml b/ci/deps/actions-38-minimum_versions.yaml index 3ab27830060b2..b1feed75bdfdd 100644 --- a/ci/deps/actions-38-minimum_versions.yaml +++ b/ci/deps/actions-38-minimum_versions.yaml @@ -49,6 +49,7 @@ dependencies: - scipy=1.7.1 - sqlalchemy=1.4.16 - tabulate=0.8.9 + - tzdata=2022.1 - xarray=0.19.0 - xlrd=2.0.1 - xlsxwriter=1.4.3 diff --git a/ci/deps/actions-39.yaml b/ci/deps/actions-39.yaml index 3cce3bda3915c..de1224cc1ef9b 100644 --- a/ci/deps/actions-39.yaml +++ b/ci/deps/actions-39.yaml @@ -47,6 +47,7 @@ dependencies: - scipy - sqlalchemy - tabulate + - tzdata>=2022.1 - xarray - xlrd - xlsxwriter diff --git a/doc/source/getting_started/install.rst b/doc/source/getting_started/install.rst index 39c9db2c883b8..bc8d80260d099 100644 --- a/doc/source/getting_started/install.rst +++ b/doc/source/getting_started/install.rst @@ -270,6 +270,15 @@ 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 Allows the use of ``zoneinfo`` timezones with pandas +========================= ================== ============================================================= + Visualization ^^^^^^^^^^^^^ diff --git a/environment.yml b/environment.yml index 0a6055d80c071..9ba875b2b4900 100644 --- a/environment.yml +++ b/environment.yml @@ -48,6 +48,7 @@ dependencies: - scipy - sqlalchemy - tabulate + - tzdata>=2022.1 - xarray - xlrd - xlsxwriter diff --git a/pandas/_libs/tslibs/timezones.pyx b/pandas/_libs/tslibs/timezones.pyx index 22a154be5fcad..a1229d47fc4d9 100644 --- a/pandas/_libs/tslibs/timezones.pyx +++ b/pandas/_libs/tslibs/timezones.pyx @@ -3,10 +3,13 @@ from datetime import ( timezone, ) +from pandas.compat._optional import import_optional_dependency + try: # py39+ import zoneinfo from zoneinfo import ZoneInfo + import_optional_dependency("tzdata", errors="raise", min_version="2022.1") except ImportError: zoneinfo = None ZoneInfo = None diff --git a/pandas/compat/_optional.py b/pandas/compat/_optional.py index ad6c6fb839f10..3801a1648f1e7 100644 --- a/pandas/compat/_optional.py +++ b/pandas/compat/_optional.py @@ -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 diff --git a/requirements-dev.txt b/requirements-dev.txt index f5dfeb8e7ff30..6ea2846e3b96d 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -39,6 +39,7 @@ s3fs scipy sqlalchemy tabulate +tzdata>=2022.1 xarray xlrd xlsxwriter From eba2fb92b097daba2a84ee7558e3dcdea3f2e6a1 Mon Sep 17 00:00:00 2001 From: Thomas Li <47963215+lithomas1@users.noreply.github.com> Date: Wed, 3 Aug 2022 06:15:58 -0700 Subject: [PATCH 06/11] update --- doc/source/getting_started/install.rst | 14 +++++++++----- environment.yml | 2 +- pandas/_libs/tslibs/timezones.pyx | 4 +++- scripts/generate_pip_deps_from_conda.py | 4 +++- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/doc/source/getting_started/install.rst b/doc/source/getting_started/install.rst index bc8d80260d099..68692253d4e0a 100644 --- a/doc/source/getting_started/install.rst +++ b/doc/source/getting_started/install.rst @@ -273,11 +273,15 @@ the method requiring that dependency is called. Timezones ^^^^^^^^^ -========================= ================== ============================================================= -Dependency Minimum Version Notes -========================= ================== ============================================================= -tzdata 2022.1 Allows the use of ``zoneinfo`` timezones with pandas -========================= ================== ============================================================= +========================= ========================= ============================================================= +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 + 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 ^^^^^^^^^^^^^ diff --git a/environment.yml b/environment.yml index 9ba875b2b4900..001f1f8927980 100644 --- a/environment.yml +++ b/environment.yml @@ -48,7 +48,7 @@ dependencies: - scipy - sqlalchemy - tabulate - - tzdata>=2022.1 + - tzdata>=2022a - xarray - xlrd - xlsxwriter diff --git a/pandas/_libs/tslibs/timezones.pyx b/pandas/_libs/tslibs/timezones.pyx index a1229d47fc4d9..5992f31e96988 100644 --- a/pandas/_libs/tslibs/timezones.pyx +++ b/pandas/_libs/tslibs/timezones.pyx @@ -9,7 +9,6 @@ try: # py39+ import zoneinfo from zoneinfo import ZoneInfo - import_optional_dependency("tzdata", errors="raise", min_version="2022.1") except ImportError: zoneinfo = None ZoneInfo = None @@ -70,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 diff --git a/scripts/generate_pip_deps_from_conda.py b/scripts/generate_pip_deps_from_conda.py index 8cb539d3b02c8..a27d089cdb9e8 100755 --- a/scripts/generate_pip_deps_from_conda.py +++ b/scripts/generate_pip_deps_from_conda.py @@ -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"} @@ -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)) From 19df15c517e53db39f2920787169cd9b67ec83c0 Mon Sep 17 00:00:00 2001 From: Thomas Li <47963215+lithomas1@users.noreply.github.com> Date: Wed, 3 Aug 2022 12:57:20 -0700 Subject: [PATCH 07/11] fix env files --- ci/deps/actions-310.yaml | 2 +- ci/deps/actions-38-minimum_versions.yaml | 2 +- ci/deps/actions-39.yaml | 2 +- scripts/validate_min_versions_in_sync.py | 5 +++++ 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ci/deps/actions-310.yaml b/ci/deps/actions-310.yaml index 192c947dc668e..260cd231ba3ef 100644 --- a/ci/deps/actions-310.yaml +++ b/ci/deps/actions-310.yaml @@ -47,7 +47,7 @@ dependencies: - scipy - sqlalchemy - tabulate - - tzdata>=2022.1 + - tzdata>=2022a - xarray - xlrd - xlsxwriter diff --git a/ci/deps/actions-38-minimum_versions.yaml b/ci/deps/actions-38-minimum_versions.yaml index b1feed75bdfdd..6e1faf3bb1d9f 100644 --- a/ci/deps/actions-38-minimum_versions.yaml +++ b/ci/deps/actions-38-minimum_versions.yaml @@ -49,7 +49,7 @@ dependencies: - scipy=1.7.1 - sqlalchemy=1.4.16 - tabulate=0.8.9 - - tzdata=2022.1 + - tzdata=2022a - xarray=0.19.0 - xlrd=2.0.1 - xlsxwriter=1.4.3 diff --git a/ci/deps/actions-39.yaml b/ci/deps/actions-39.yaml index de1224cc1ef9b..849fabefd223f 100644 --- a/ci/deps/actions-39.yaml +++ b/ci/deps/actions-39.yaml @@ -47,7 +47,7 @@ dependencies: - scipy - sqlalchemy - tabulate - - tzdata>=2022.1 + - tzdata>=2022a - xarray - xlrd - xlsxwriter diff --git a/scripts/validate_min_versions_in_sync.py b/scripts/validate_min_versions_in_sync.py index 4dbf6a4cdcef8..1b937673672f8 100755 --- a/scripts/validate_min_versions_in_sync.py +++ b/scripts/validate_min_versions_in_sync.py @@ -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") @@ -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() @@ -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: From f36bbe6d36c9e49c3da4c65dda989be30af54a8d Mon Sep 17 00:00:00 2001 From: Thomas Li <47963215+lithomas1@users.noreply.github.com> Date: Fri, 5 Aug 2022 06:35:30 -0700 Subject: [PATCH 08/11] fix typing --- pandas/conftest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index 2a3e09b56148b..ba10ab575d2c0 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -87,8 +87,8 @@ # "not available" without tzdata/IANA tz data. # We will set zoneinfo to not found in this case try: - zoneinfo.ZoneInfo("UTC") - except zoneinfo.ZoneInfoNotFoundError: + 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 From 093ca1ddf1e9d91942931adda669bdc4a4e1d6f2 Mon Sep 17 00:00:00 2001 From: Thomas Li <47963215+lithomas1@users.noreply.github.com> Date: Fri, 5 Aug 2022 06:36:29 -0700 Subject: [PATCH 09/11] fix formatting --- pandas/conftest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index ba10ab575d2c0..babd88b60b366 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -87,8 +87,8 @@ # "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.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 From 64de406e086cebf9c228b3020b0d1ab49e52bccf Mon Sep 17 00:00:00 2001 From: Thomas Li <47963215+lithomas1@users.noreply.github.com> Date: Mon, 8 Aug 2022 20:45:11 -0700 Subject: [PATCH 10/11] Update tzdata note --- doc/source/getting_started/install.rst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/doc/source/getting_started/install.rst b/doc/source/getting_started/install.rst index b25d79fc9f2e2..4a2354b2dc23d 100644 --- a/doc/source/getting_started/install.rst +++ b/doc/source/getting_started/install.rst @@ -277,10 +277,14 @@ 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 + 2022a(for system tzdata) **Note**: You only need to install the pypi package if your 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. + + If you would like to keep your system tzdata version updated, + it is recommended to use the ``tzdata`` package from + conda-forge. ========================= ========================= ============================================================= Visualization From 9a973f0fd890c320a175c14ac8bf99baa6089078 Mon Sep 17 00:00:00 2001 From: Thomas Li <47963215+lithomas1@users.noreply.github.com> Date: Tue, 9 Aug 2022 06:55:20 -0700 Subject: [PATCH 11/11] code checks --- doc/source/getting_started/install.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/getting_started/install.rst b/doc/source/getting_started/install.rst index 4a2354b2dc23d..e24528e611c12 100644 --- a/doc/source/getting_started/install.rst +++ b/doc/source/getting_started/install.rst @@ -281,7 +281,7 @@ tzdata 2022.1(pypi)/ Allows the use of ``zoneinfo 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. - + If you would like to keep your system tzdata version updated, it is recommended to use the ``tzdata`` package from conda-forge.