Skip to content

GH-15047: [Python]: switch from pytz to zoneinfo by default for string to tzinfo conversion#49694

Open
jorisvandenbossche wants to merge 5 commits intoapache:mainfrom
jorisvandenbossche:gh-15047-pytz-to-zoneinfo
Open

GH-15047: [Python]: switch from pytz to zoneinfo by default for string to tzinfo conversion#49694
jorisvandenbossche wants to merge 5 commits intoapache:mainfrom
jorisvandenbossche:gh-15047-pytz-to-zoneinfo

Conversation

@jorisvandenbossche
Copy link
Copy Markdown
Member

@jorisvandenbossche jorisvandenbossche commented Apr 8, 2026

Rationale for this change

zoneinfo is available starting with Python 3.9, so we can now assume that it is available, and so we can switch from returning pytz timezones by default to return zoneinfo timezones (or datetime.timezone for fixed offsets).

Only keeping pytz as fallback for strings that are not supported by zoneinfo but were supported by pytz. Later, we should maybe deprecate that fallback.

Generally we should move away from using pytz, since the core functionality of having time zones is now available in the standard library (zoneinfo), and because the pytz package has several warts / incompatibilities with stdlib datetime (https://blog.ganssle.io/articles/2018/03/pytz-fastest-footgun.html)

What changes are included in this PR?

Whenever we create a python timezone object, which is when converting to pandas or when converting to a datetime.datetime object:

In either case, when preferring zoneinfo, we still fall back to pytz for named timezones if zoneinfo does not recognize the zone name (apparently pytz can have some common (older) aliases that might not always work with zoneinfo).
This fallback is something we could deprecate and remove later on (so we can eventually remove all usage of pytz)

Are these changes tested?

Yes

Are there any user-facing changes?

This PR includes breaking changes to public APIs.

It is a different object that we return (different class, i.e. zoneinfo.ZoneInfo instead of a pytz.tzinfo.BaseTzInfo, both are still subclasses of datetime.tzinfo), which has some differences in the API, so for people relying on that, this is a breaking change.

For the conversion to pandas, pandas itself has made this breaking change anyhow, so for those cases it aligns with that change of pandas.

@jorisvandenbossche jorisvandenbossche marked this pull request as draft April 8, 2026 18:03
@github-actions github-actions bot added the awaiting committer review Awaiting committer review label Apr 8, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 8, 2026

⚠️ GitHub issue #15047 has been automatically assigned in GitHub to PR creator.

@jorisvandenbossche
Copy link
Copy Markdown
Member Author

@github-actions crossbow submit test-pandas

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 9, 2026

Revision: dc184fe

Submitted crossbow builds: ursacomputing/crossbow @ actions-cdf269df89

Task Status
test-conda-python-3.10-pandas-1.3.4-numpy-1.21.2 GitHub Actions
test-conda-python-3.11-pandas-latest-numpy-latest GitHub Actions
test-conda-python-3.12-pandas-latest-numpy-1.26 GitHub Actions
test-conda-python-3.12-pandas-latest-numpy-latest GitHub Actions
test-conda-python-3.13-pandas-nightly-numpy-nightly GitHub Actions
test-conda-python-3.13-pandas-upstream_devel-numpy-nightly GitHub Actions

@jorisvandenbossche
Copy link
Copy Markdown
Member Author

@github-actions crossbow submit -g python

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 9, 2026

Revision: c2c973a

Submitted crossbow builds: ursacomputing/crossbow @ actions-02d567dab2

Task Status
example-python-minimal-build-fedora-conda GitHub Actions
example-python-minimal-build-ubuntu-venv GitHub Actions
test-conda-python-3.10 GitHub Actions
test-conda-python-3.10-hdfs-2.9.2 GitHub Actions
test-conda-python-3.10-hdfs-3.2.1 GitHub Actions
test-conda-python-3.10-pandas-1.3.4-numpy-1.21.2 GitHub Actions
test-conda-python-3.11 GitHub Actions
test-conda-python-3.11-dask-latest GitHub Actions
test-conda-python-3.11-dask-upstream_devel GitHub Actions
test-conda-python-3.11-hypothesis GitHub Actions
test-conda-python-3.11-pandas-latest-numpy-latest GitHub Actions
test-conda-python-3.11-spark-master GitHub Actions
test-conda-python-3.12 GitHub Actions
test-conda-python-3.12-cpython-debug GitHub Actions
test-conda-python-3.12-pandas-latest-numpy-1.26 GitHub Actions
test-conda-python-3.12-pandas-latest-numpy-latest GitHub Actions
test-conda-python-3.13 GitHub Actions
test-conda-python-3.13-pandas-nightly-numpy-nightly GitHub Actions
test-conda-python-3.13-pandas-upstream_devel-numpy-nightly GitHub Actions
test-conda-python-3.14 GitHub Actions
test-conda-python-emscripten GitHub Actions
test-debian-13-python-3-amd64 GitHub Actions
test-debian-13-python-3-i386 GitHub Actions
test-fedora-42-python-3 GitHub Actions
test-ubuntu-22.04-python-3 GitHub Actions
test-ubuntu-22.04-python-313-freethreading GitHub Actions
test-ubuntu-24.04-python-3 GitHub Actions

@jorisvandenbossche jorisvandenbossche marked this pull request as ready for review April 9, 2026 12:24
@jorisvandenbossche
Copy link
Copy Markdown
Member Author

@github-actions crossbow submit -g wheel

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 9, 2026

Revision: c2c973a

Submitted crossbow builds: ursacomputing/crossbow @ actions-4c3b50812b

Task Status
python-sdist GitHub Actions
wheel-macos-monterey-cp310-cp310-amd64 GitHub Actions
wheel-macos-monterey-cp310-cp310-arm64 GitHub Actions
wheel-macos-monterey-cp311-cp311-amd64 GitHub Actions
wheel-macos-monterey-cp311-cp311-arm64 GitHub Actions
wheel-macos-monterey-cp312-cp312-amd64 GitHub Actions
wheel-macos-monterey-cp312-cp312-arm64 GitHub Actions
wheel-macos-monterey-cp313-cp313-amd64 GitHub Actions
wheel-macos-monterey-cp313-cp313-arm64 GitHub Actions
wheel-macos-monterey-cp313-cp313t-amd64 GitHub Actions
wheel-macos-monterey-cp313-cp313t-arm64 GitHub Actions
wheel-macos-monterey-cp314-cp314-amd64 GitHub Actions
wheel-macos-monterey-cp314-cp314-arm64 GitHub Actions
wheel-macos-monterey-cp314-cp314t-amd64 GitHub Actions
wheel-macos-monterey-cp314-cp314t-arm64 GitHub Actions
wheel-manylinux-2-28-cp310-cp310-amd64 GitHub Actions
wheel-manylinux-2-28-cp310-cp310-arm64 GitHub Actions
wheel-manylinux-2-28-cp311-cp311-amd64 GitHub Actions
wheel-manylinux-2-28-cp311-cp311-arm64 GitHub Actions
wheel-manylinux-2-28-cp312-cp312-amd64 GitHub Actions
wheel-manylinux-2-28-cp312-cp312-arm64 GitHub Actions
wheel-manylinux-2-28-cp313-cp313-amd64 GitHub Actions
wheel-manylinux-2-28-cp313-cp313-arm64 GitHub Actions
wheel-manylinux-2-28-cp313-cp313t-amd64 GitHub Actions
wheel-manylinux-2-28-cp313-cp313t-arm64 GitHub Actions
wheel-manylinux-2-28-cp314-cp314-amd64 GitHub Actions
wheel-manylinux-2-28-cp314-cp314-arm64 GitHub Actions
wheel-manylinux-2-28-cp314-cp314t-amd64 GitHub Actions
wheel-manylinux-2-28-cp314-cp314t-arm64 GitHub Actions
wheel-musllinux-1-2-cp310-cp310-amd64 GitHub Actions
wheel-musllinux-1-2-cp310-cp310-arm64 GitHub Actions
wheel-musllinux-1-2-cp311-cp311-amd64 GitHub Actions
wheel-musllinux-1-2-cp311-cp311-arm64 GitHub Actions
wheel-musllinux-1-2-cp312-cp312-amd64 GitHub Actions
wheel-musllinux-1-2-cp312-cp312-arm64 GitHub Actions
wheel-musllinux-1-2-cp313-cp313-amd64 GitHub Actions
wheel-musllinux-1-2-cp313-cp313-arm64 GitHub Actions
wheel-musllinux-1-2-cp313-cp313t-amd64 GitHub Actions
wheel-musllinux-1-2-cp313-cp313t-arm64 GitHub Actions
wheel-musllinux-1-2-cp314-cp314-amd64 GitHub Actions
wheel-musllinux-1-2-cp314-cp314-arm64 GitHub Actions
wheel-musllinux-1-2-cp314-cp314t-amd64 GitHub Actions
wheel-musllinux-1-2-cp314-cp314t-arm64 GitHub Actions
wheel-windows-cp310-cp310-amd64 GitHub Actions
wheel-windows-cp311-cp311-amd64 GitHub Actions
wheel-windows-cp312-cp312-amd64 GitHub Actions
wheel-windows-cp313-cp313-amd64 GitHub Actions
wheel-windows-cp313-cp313t-amd64 GitHub Actions
wheel-windows-cp314-cp314-amd64 GitHub Actions
wheel-windows-cp314-cp314t-amd64 GitHub Actions

@jorisvandenbossche
Copy link
Copy Markdown
Member Author

As far as I can see, all failures in the above crossbow builds (after the last update) are unrelated (docker/git/download failures)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant