-
-
Notifications
You must be signed in to change notification settings - Fork 684
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
Use zoneinfo for timezone handling instead of pytz #1179
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1179 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 10 10
Lines 2324 2334 +10
Branches 357 357
=========================================
+ Hits 2324 2334 +10 ☔ View full report in Codecov by Sentry. |
pyproject.toml
Outdated
@@ -46,7 +46,6 @@ test = [ | |||
"pytest", | |||
"pytest-cov", | |||
"pytest-mock", | |||
"pytz==2021.1", | |||
"simplejson==3.*", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need to add a dependency on the backport like this:
backports.zoneinfo = {version = "0.2.1", markers = "python_version < '3.9'"}
from dateutil.zoneinfo import get_zonefile_instance | ||
|
||
|
||
def make_full_tz_list(): | ||
dateutil_zones = set(get_zonefile_instance().zones) | ||
pytz_zones = set(pytz.all_timezones) | ||
return dateutil_zones.union(pytz_zones) | ||
zoneinfo_zones = set(zoneinfo.available_timezones()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this have the proper coverage for all timezones? We primarily used pytz to get greater coverage of time zones for the sake of tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just compared them and it does have the same coverage as pytz (Windows 11). However, from the zoneinfo docs:
The zoneinfo module does not directly provide time zone data, and instead pulls time zone information from the system time zone database or the first-party PyPI package tzdata, if available. Some systems, including notably Windows systems, do not have an IANA database available, and so for projects targeting cross-platform compatibility that require time zone data, it is recommended to declare a dependency on tzdata. If neither system data nor tzdata are available, all calls to ZoneInfo will raise ZoneInfoNotFoundError.
tests/test_arrow.py
Outdated
@@ -57,9 +56,9 @@ def test_init(self): | |||
assert result._datetime == self.expected | |||
|
|||
# regression tests for issue #626 | |||
def test_init_pytz_timezone(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a separate test for pytz and another for zoneinfo? I don't think we should be removing pytz and closing the open issue for the sake of the tests. There is still a use-case for passing in a pytz timezone into Arrow, especially if someone has not yet adopted zoneinfo.
If pytz is not used in the core arrow code and only in the test code (it is only pulled in via requirements-tests.txt
, I think we need another CR that focuses on adding support for Zoneinfo natively throughout rather than using dateutil, which is our primary means of doing timezones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure
Hi @saranti mind getting this PR up to date? Then we can merge it in :) |
Thanks @saranti , but it seems like the conflicts are still present and GH is not allowing us to re-run the actions to test |
No worries. That looks better but it looks like there's a linting issue caused by c2dfa12 |
Odd indeed, this must have come as a result of the upgrades we made to the actions. I merged the revert, and updated branch @krisfremen. Would it be possible to reapply the PR you reverted once we merge? |
Pull Request Checklist
Thank you for taking the time to improve Arrow! Before submitting your pull request, please check all appropriate boxes:
tox
ormake test
to find out!).tox -e lint
ormake lint
to find out!).master
branch.If you have any questions about your code changes or any of the points above, please submit your questions along with the pull request and we will try our best to help!
Description of Changes
Closes #1175. Remove all pytz code and replace it with the equivalent from zoneinfo and use a backport for python versions <3.9.