Skip to content

Commit 82875c7

Browse files
committed
refactor: deprecate pytz in favor of builtin zoneinfo
1 parent 603ede0 commit 82875c7

16 files changed

Lines changed: 526 additions & 406 deletions

ci/requirements-py3.10-min.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ dependencies:
99
- pytest-mock
1010
- pytest-timeout
1111
- python=3.10
12-
- pytz
1312
- requests
1413
- pip:
1514
- h5py==3.6.0

ci/requirements-py3.10.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ dependencies:
1919
- pytest-rerunfailures
2020
- conda-forge::pytest-remotedata # version in default channel is old
2121
- python=3.10
22-
- pytz
2322
- requests
2423
- scipy >= 1.7.2
2524
- statsmodels

ci/requirements-py3.11.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ dependencies:
1919
- pytest-rerunfailures
2020
- conda-forge::pytest-remotedata # version in default channel is old
2121
- python=3.11
22-
- pytz
2322
- requests
2423
- scipy >= 1.7.2
2524
- statsmodels

ci/requirements-py3.12.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ dependencies:
1919
- pytest-rerunfailures
2020
- conda-forge::pytest-remotedata # version in default channel is old
2121
- python=3.12
22-
- pytz
2322
- requests
2423
- scipy >= 1.7.2
2524
- statsmodels

ci/requirements-py3.13.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ dependencies:
1919
- pytest-rerunfailures
2020
- conda-forge::pytest-remotedata # version in default channel is old
2121
- python=3.13
22-
- pytz
2322
- requests
2423
- scipy >= 1.7.2
2524
- statsmodels

ci/requirements-py3.14.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ dependencies:
1919
- pytest-rerunfailures
2020
- conda-forge::pytest-remotedata # version in default channel is old
2121
- python=3.14
22-
- pytz
2322
- requests
2423
- scipy >= 1.7.2
2524
- statsmodels

docs/tutorials/solarposition.ipynb

Lines changed: 483 additions & 340 deletions
Large diffs are not rendered by default.

pvlib/iotools/pvgis.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import requests
2121
import numpy as np
2222
import pandas as pd
23-
import pytz
23+
import zoneinfo
2424
from pvlib.iotools import read_epw
2525

2626
URL = 'https://re.jrc.ec.europa.eu/api/'
@@ -413,10 +413,10 @@ def _coerce_and_roll_tmy(tmy_data, tz, year):
413413
re-interpreted as zero / UTC.
414414
"""
415415
if tz:
416-
tzname = pytz.timezone(f'Etc/GMT{-tz:+d}')
416+
tzname = zoneinfo.ZoneInfo(f'Etc/GMT{-tz:+d}')
417417
else:
418418
tz = 0
419-
tzname = pytz.timezone('UTC')
419+
tzname = zoneinfo.ZoneInfo('UTC')
420420
new_index = pd.DatetimeIndex([
421421
timestamp.replace(year=year, tzinfo=tzname)
422422
for timestamp in tmy_data.index],

pvlib/location.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
import pathlib
88
import datetime
9+
import warnings
910
import zoneinfo
1011

1112
import pandas as pd
12-
import pytz
1313
import h5py
1414

1515
from pvlib import solarposition, clearsky, atmosphere, irradiance
@@ -22,13 +22,11 @@ class Location:
2222
time zone, and altitude data associated with a particular geographic
2323
location. You can also assign a name to a location object.
2424
25-
Location objects have two time-zone attributes:
25+
Location objects have a time-zone attribute:
2626
2727
* ``tz`` is an IANA time-zone string.
28-
* ``pytz`` is a pytz-based time-zone object (read only).
2928
30-
The read-only ``pytz`` attribute will stay in sync with any changes made
31-
using ``tz``.
29+
The ``pytz`` attribute was removed. Use ``tz`` property instead.
3230
3331
Location objects support the print method.
3432
@@ -47,8 +45,7 @@ class Location:
4745
list of valid name strings. An `int` or `float` must be a whole-number
4846
hour offsets from UTC that can be converted to the IANA-supported
4947
'Etc/GMT-N' format. (Note the limited range of the offset N and its
50-
sign-change convention.) Time zones from the pytz and zoneinfo packages
51-
may also be passed here, as they are subclasses of datetime.tzinfo.
48+
sign-change convention.) Time zones from the zoneinfo packages may also be passed here.
5249
5350
The `tz` attribute is represented as a valid IANA time zone name
5451
string.
@@ -118,7 +115,7 @@ def tz(self, tz_):
118115

119116
self._zoneinfo = zoneinfo.ZoneInfo(f"Etc/GMT{-int(tz_):+d}")
120117
elif isinstance(tz_, datetime.tzinfo):
121-
# Includes time zones generated by pytz and zoneinfo packages.
118+
# Includes time zones generated by zoneinfo packages.
122119
self._zoneinfo = zoneinfo.ZoneInfo(str(tz_))
123120
else:
124121
raise TypeError(
@@ -127,11 +124,6 @@ def tz(self, tz_):
127124
"datetime.tzinfo object (including subclasses)"
128125
)
129126

130-
@property
131-
def pytz(self):
132-
"""The location's pytz time zone (read only)."""
133-
return pytz.timezone(str(self._zoneinfo))
134-
135127
@classmethod
136128
def from_tmy(cls, tmy_metadata, tmy_data=None, **kwargs):
137129
"""

pvlib/solarposition.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,11 +1360,11 @@ def hour_angle(times, longitude, equation_of_time):
13601360
Corresponding timestamps, must be localized to the timezone for the
13611361
``longitude``.
13621362
1363-
A `pytz.exceptions.AmbiguousTimeError` will be raised if any of the
1364-
given times are on a day when the local daylight savings transition
1365-
happens at midnight. If you're working with such a timezone,
1366-
consider converting to a non-DST timezone (e.g. GMT-4) before
1367-
calling this function.
1363+
An error (AmbiguousTimeError in older pandas, ValueError in newer)
1364+
will be raised if any of the given times are on a day when the local
1365+
daylight savings transition happens at midnight. If you're working
1366+
with such a timezone, consider converting to a non-DST timezone
1367+
(e.g. GMT-4) before calling this function.
13681368
longitude : numeric
13691369
Longitude in degrees
13701370
equation_of_time : numeric

0 commit comments

Comments
 (0)