-
Notifications
You must be signed in to change notification settings - Fork 1.2k
refactor: deprecate pytz in favor of builtin zoneinfo #2757
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
base: main
Are you sure you want to change the base?
Changes from all commits
6a5c5d3
6e90468
6ce566e
a3a030f
2f58cc6
05d2781
dd89c33
15e60b0
dac983e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,7 @@ | |
| import requests | ||
| import numpy as np | ||
| import pandas as pd | ||
| import pytz | ||
| import zoneinfo | ||
| from pvlib.iotools import read_epw | ||
|
|
||
| URL = 'https://re.jrc.ec.europa.eu/api/' | ||
|
|
@@ -413,10 +413,10 @@ def _coerce_and_roll_tmy(tmy_data, tz, year): | |
| re-interpreted as zero / UTC. | ||
| """ | ||
| if tz: | ||
| tzname = pytz.timezone(f'Etc/GMT{-tz:+d}') | ||
| tzname = zoneinfo.ZoneInfo(f'Etc/GMT{-tz:+d}') # noqa: E231 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't see the commit history, did you add
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @echedey-ls yes it was a false positive, flake8 insisted on putting a space after the : |
||
| else: | ||
| tz = 0 | ||
| tzname = pytz.timezone('UTC') | ||
| tzname = zoneinfo.ZoneInfo('UTC') | ||
| new_index = pd.DatetimeIndex([ | ||
| timestamp.replace(year=year, tzinfo=tzname) | ||
| for timestamp in tmy_data.index], | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |||||
|
|
||||||
| from pvlib import solarposition, clearsky, atmosphere, irradiance | ||||||
| from pvlib.tools import _degrees_to_index | ||||||
| from pvlib._deprecation import warn_deprecated | ||||||
|
|
||||||
|
|
||||||
| class Location: | ||||||
|
|
@@ -22,13 +23,11 @@ class Location: | |||||
| time zone, and altitude data associated with a particular geographic | ||||||
| location. You can also assign a name to a location object. | ||||||
|
|
||||||
| Location objects have two time-zone attributes: | ||||||
| Location objects have a time-zone attribute ``tz`` (IANA timezone string). | ||||||
|
|
||||||
| * ``tz`` is an IANA time-zone string. | ||||||
| * ``pytz`` is a pytz-based time-zone object (read only). | ||||||
| .. deprecated:: 0.15.2 | ||||||
|
|
||||||
| The read-only ``pytz`` attribute will stay in sync with any changes made | ||||||
| using ``tz``. | ||||||
| The ``pytz`` attribute is deprecated. Use ``tz`` instead. | ||||||
|
JoLo90 marked this conversation as resolved.
|
||||||
|
|
||||||
| Location objects support the print method. | ||||||
|
|
||||||
|
|
@@ -47,8 +46,8 @@ class Location: | |||||
| list of valid name strings. An `int` or `float` must be a whole-number | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| hour offsets from UTC that can be converted to the IANA-supported | ||||||
| 'Etc/GMT-N' format. (Note the limited range of the offset N and its | ||||||
| sign-change convention.) Time zones from the pytz and zoneinfo packages | ||||||
| may also be passed here, as they are subclasses of datetime.tzinfo. | ||||||
| sign-change convention.) Time zones from the zoneinfo packages may also | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| be passed here. | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| The `tz` attribute is represented as a valid IANA time zone name | ||||||
| string. | ||||||
|
|
@@ -108,17 +107,19 @@ def tz(self, tz_): | |||||
| if isinstance(tz_, str): | ||||||
| self._zoneinfo = zoneinfo.ZoneInfo(tz_) | ||||||
| elif isinstance(tz_, int): | ||||||
| self._zoneinfo = zoneinfo.ZoneInfo(f"Etc/GMT{-tz_:+d}") | ||||||
| tz_str = f"Etc/GMT{-tz_:+d}" # noqa: E231 | ||||||
| self._zoneinfo = zoneinfo.ZoneInfo(tz_str) | ||||||
| elif isinstance(tz_, float): | ||||||
| if tz_ % 1 != 0: | ||||||
| raise TypeError( | ||||||
| "Floating-point tz has non-zero fractional part: " | ||||||
| f"{tz_}. Only whole-number offsets are supported." | ||||||
| ) | ||||||
|
|
||||||
| self._zoneinfo = zoneinfo.ZoneInfo(f"Etc/GMT{-int(tz_):+d}") | ||||||
| tz_str = f"Etc/GMT{-int(tz_):+d}" # noqa: E231 | ||||||
| self._zoneinfo = zoneinfo.ZoneInfo(tz_str) | ||||||
| elif isinstance(tz_, datetime.tzinfo): | ||||||
| # Includes time zones generated by pytz and zoneinfo packages. | ||||||
| # Includes time zones generated by zoneinfo packages. | ||||||
| self._zoneinfo = zoneinfo.ZoneInfo(str(tz_)) | ||||||
| else: | ||||||
| raise TypeError( | ||||||
|
|
@@ -128,8 +129,20 @@ def tz(self, tz_): | |||||
| ) | ||||||
|
|
||||||
| @property | ||||||
| def pytz(self): | ||||||
| """The location's pytz time zone (read only).""" | ||||||
| def pytz(self): # pragma: no cover | ||||||
| """The location's pytz time zone (read only). | ||||||
|
|
||||||
| .. deprecated:: 0.15.2 | ||||||
| The ``pytz`` attribute is deprecated. Use the ``tz`` property | ||||||
| instead. | ||||||
| """ | ||||||
| warn_deprecated( | ||||||
| since='0.15.2', | ||||||
| removal='0.17.0', | ||||||
| name='pytz', | ||||||
| obj_type='attribute', | ||||||
| alternative='tz', | ||||||
| ) | ||||||
| return pytz.timezone(str(self._zoneinfo)) | ||||||
|
|
||||||
| @classmethod | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -1360,11 +1360,11 @@ def hour_angle(times, longitude, equation_of_time): | |||||
| Corresponding timestamps, must be localized to the timezone for the | ||||||
| ``longitude``. | ||||||
|
|
||||||
| A `pytz.exceptions.AmbiguousTimeError` will be raised if any of the | ||||||
| given times are on a day when the local daylight savings transition | ||||||
| happens at midnight. If you're working with such a timezone, | ||||||
| consider converting to a non-DST timezone (e.g. GMT-4) before | ||||||
| calling this function. | ||||||
| ``AmbiguousTimeError`` in older pandas, ``ValueError`` in newer | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| will be raised if any of the given times are on a day when the local | ||||||
| daylight savings transition happens at midnight. If you're working | ||||||
| with such a timezone, consider converting to a non-DST timezone | ||||||
| (e.g. GMT-4) before calling this function. | ||||||
| longitude : numeric | ||||||
| Longitude in degrees | ||||||
| equation_of_time : numeric | ||||||
|
|
||||||
|
JoLo90 marked this conversation as resolved.
|
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.