8000 Python and dependency bounds illustration by markcampanelli · Pull Request #2339 · pvlib/pvlib-python · GitHub
[go: up one dir, main page]

Skip to content

Python and dependency bounds illustration #2339

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

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
8000 Loading
Diff view
Diff view
Prev Previous commit
Revert to just pyproject.toml changes (no zoneinfo changes)
  • Loading branch information
markcampanelli committed Dec 23, 2024
commit 8aee6cd661a1fcc0f26f3793e2da662fcb3011fe
2 changes: 1 addition & 1 deletion ci/requirements-py3.10.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dependencies:
- pytest-rerunfailures
- conda-forge::pytest-remotedata # version in default channel is old
- python 8000 =3.10
# - pytz
- pytz
- requests
- scipy >= 1.6.0
- statsmodels
Expand Down
2 changes: 1 addition & 1 deletion ci/requirements-py3.11.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dependencies:
- pytest-rerunfailures
- conda-forge::pytest-remotedata # version in default channel is old
- python=3.11
# - pytz
- pytz
- requests
- scipy >= 1.6.0
- statsmodels
Expand Down
2 changes: 1 addition & 1 deletion ci/requirements-py3.12.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dependencies:
- pytest-rerunfailures
- conda-forge::pytest-remotedata # version in default channel is old
- python=3.12
# - pytz
- pytz
- requests
- scipy >= 1.6.0
- statsmodels
Expand Down
2 changes: 1 addition & 1 deletion ci/requirements-py3.9-min.yml
< 8000 td id="diff-391a21061f12414867368b9ca23548e471a1d85f94cf9594e966117a3a28c634R10" data-line-number="10" class="blob-num blob-num-context js-linkable-line-number js-blob-rnum">
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies:
- pytest-mock
- pytest-timeout
- python=3.9
# - pytz
- pytz
- requests
- pip:
- h5py==3.0.0
Expand Down
2 changes: 1 addition & 1 deletion ci/requirements-py3.9.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dependencies:
- pytest-rerunfailures
- conda-forge::pytest-remotedata # version in default channel is old
- python=3.9
# - pytz
- pytz
- requests
- scipy >= 1.6.0
- statsmodels
Expand Down
4 changes: 2 additions & 2 deletions docs/sphinx/source/whatsnew/v0.11.3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ Documentation

Testing
~~~~~~~
* Add tests for time conversions in tools package. (:issue:`2340`, :pull:`2341`)


Requirements
Expand All @@ -27,4 +26,5 @@ Requirements

Contributors
~~~~~~~~~~~~
* Mark Campanellli (:ghuser:`markcampanelli`)


32 changes: 16 additions & 16 deletions docs/tutorials/solarposition.ipynb

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions pvlib/iotools/pvgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@
import io
import json
from pathlib import Path
from zoneinfo import ZoneInfo

import requests
import numpy as np
import pandas as pd

import pytz
from pvlib.iotools import read_epw, parse_epw

URL = 'https://re.jrc.ec.europa.eu/api/'
Expand Down Expand Up @@ -400,10 +398,10 @@ def _coerce_and_roll_tmy(tmy_data, tz, year):
re-interpreted as zero / UTC.
"""
if tz:
tzname = ZoneInfo(f'Etc/GMT{-tz:+d}')
tzname = pytz.timezone(f'Etc/GMT{-tz:+d}')
else:
tz = 0
tzname = ZoneInfo('UTC')
tzname = pytz.timezone('UTC')
new_index = pd.DatetimeIndex([
F438 timestamp.replace(year=year, tzinfo=tzname)
for timestamp in tmy_data.index],
Expand Down
77 changes: 31 additions & 46 deletions pvlib/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@

# Will Holmgren, University of Arizona, 2014-2016.

import datetime
import pathlib
from zoneinfo import ZoneInfo
import datetime

import h5py
import pandas as pd
# import pytz
import pytz
import h5py

from pvlib import atmosphere, clearsky, irradiance, solarposition
# from pvlib._deprecation import warn_deprecated
from pvlib import solarposition, clearsky, atmosphere, irradiance
from pvlib.tools import _degrees_to_index


Expand All @@ -23,12 +21,10 @@ class Location:
timezone, and altitude data associated with a particular
geographic location. You can also assign a name to a location object.

Location objects have one timezone attribute:

* ``tz`` is a IANA-compatible standard-library zoneinfo.ZoneInfo.
Location objects have two timezone attributes:

Thus, the passed timezone must be representable by one of the values in
zoneinfo.available_timezones().
* ``tz`` is a IANA timezone string.
* ``pytz`` is a pytz timezone object.

Location objects support the print method.

Expand All @@ -42,13 +38,12 @@ class Location:
Positive is east of the prime meridian.
Use decimal degrees notation.

tz : str, int, float, zoneinfo.ZoneInfo, datetime.timezone, or pytz
timezone (deprecated), default 'UTC'.
See http://en.wikipedia.org/wiki/List_of_tz_database_time_zones for a
list of valid time zone strings, or use the function
zoneinfo.available_timezones().
ints and floats must be in hours N from UTC, and are converted to the
Etc/GMT+N or Etc/GMT-N format depending on the sign of N.
tz : str, int, float, or pytz.timezone, default 'UTC'.
See
http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
for a list of valid time zones.
pytz.timezone objects will be converted to strings.
ints and floats must be in hours from UTC.

altitude : float, optional
Altitude from sea level in meters.
Expand All @@ -64,43 +59,33 @@ class Location:
pvlib.pvsystem.PVSystem
"""

def __init__(
self, latitude, longitude, tz='UTC', altitude=None, name=None
):

if name is None:
name = ""
< 10000 br>
self.name = name
def __init__(self, latitude, longitude, tz='UTC', altitude=None,
name=None):

self.latitude = latitude
self.longitude = longitude

if isinstance(tz, str):
self.tz = tz
self.pytz = pytz.timezone(tz)
elif isinstance(tz, datetime.timezone):
self.tz = 'UTC'
self.pytz = pytz.UTC
elif isinstance(tz, datetime.tzinfo):
self.tz = tz.zone
self.pytz = tz
elif isinstance(tz, (int, float)):
self.tz = tz
self.pytz = pytz.FixedOffset(tz*60)
else:
raise TypeError('Invalid tz specification')

if altitude is None:
altitude = lookup_altitude(latitude, longitude)

self.altitude = altitude

if isinstance(tz, str):
self.tz = ZoneInfo(tz)
elif isinstance(tz, int):
self.tz = ZoneInfo(f"Etc/GMT{-tz:+d}")
elif isinstance(tz, float):
self.tz = ZoneInfo(f"Etc/GMT{int(-tz):+d}")
elif isinstance(tz, ZoneInfo):
self.tz = tz
elif isinstance(tz, datetime.timezone):
self.tz = ZoneInfo(str(tz))
# elif isinstance(tz, pytz.BaseTzInfo):
# warn_deprecated(
# "0.11.3",
# message='pytz-based timezones are deprecated for locations',
# alternative='use zoneinfo.ZoneInfo from standard library',
# obj_type='function argument type',
# )
# self.tz = ZoneInfo(tz.zone)
else:
raise TypeError(f'Invalid tz specification: {tz}')
self.name = name

def __repr__(self):
attrs = ['name', 'latitude', 'longitude', 'altitude', 'tz']
Expand Down
1 change: 1 addition & 0 deletions pvlib/temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import numpy as np
import pandas as pd
from pvlib.tools import sind
from pvlib._deprecation import warn_deprecated
from pvlib.tools import _get_sample_intervals
import scipy
import scipy.constants
Expand Down
3 changes: 2 additions & 1 deletion pvlib/tests/iotools/test_midc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pandas as pd
import pytest
import pytz

from pvlib.iotools import midc
from ..conftest import DATA_DIR, RERUNS, RERUNS_DELAY
Expand Down Expand Up @@ -42,7 +43,7 @@ def test_midc__format_index_tz_conversion():
data = pd.read_csv(MIDC_TESTFILE)
data = data.rename(columns={'MST': 'PST'})
data = midc._format_index(data)
assert str(data.index[0].tz) == 'Etc/GMT+8'
assert data.index[0].tz == pytz.timezone('Etc/GMT+8')


def test_midc__format_index_raw():
Expand Down
4 changes: 2 additions & 2 deletions pvlib/tests/test_clearsky.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from collections import OrderedDict
from zoneinfo import ZoneInfo

import numpy as np
from numpy import nan
import pandas as pd
import pytz
from scipy.linalg import hankel

import pytest
Expand Down Expand Up @@ -758,7 +758,7 @@ def test_bird():
times = pd.date_range(start='1/1/2015 0:00', end='12/31/2015 23:00',
freq='h')
tz = -7 # test timezone
gmt_tz = ZoneInfo(f"Etc/GMT{-tz:+}")
gmt_tz = pytz.timezone('Etc/GMT%+d' % -(tz))
times = times.tz_localize(gmt_tz) # set timezone
times_utc = times.tz_convert('UTC')
# match test data from BIRD_08_16_2012.xls
Expand Down
32 changes: 13 additions & 19 deletions pvlib/tests/test_location.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import datetime
from unittest.mock import ANY
from zoneinfo import ZoneInfo, ZoneInfoNotFoundError

import numpy as np
from numpy import nan
import pandas as pd
from .conftest import assert_frame_equal, assert_index_equal

import pytest
# import pytz

import pytz
from pytz.exceptions import UnknownTimeZoneError

import pvlib
from pvlib import location
Expand All @@ -26,23 +27,16 @@ def test_location_all():
Location(32.2, -111, 'US/Arizona', 700, 'Tucson')


@pytest.mark.parametrize(
'tz',
[
# pytz.timezone('US/Arizona'),
ZoneInfo('US/Arizona'),
'America/Phoenix',
-7,
-7.0,
datetime.timezone.utc,
]
)
@pytest.mark.parametrize('tz', [
pytz.timezone('US/Arizona'), 'America/Phoenix', -7, -7.0,
datetime.timezone.utc
])
def test_location_tz(tz):
Location(32.2, -111, tz)


def test_location_invalid_tz():
with pytest.raises(ZoneInfoNotFoundError):
with pytest.raises(UnknownTimeZoneError):
Location(32.2, -111, 'invalid')


Expand All @@ -64,8 +58,8 @@ def test_location_print_all():
assert tus.__str__() == expected_str


def test_location_print_zoneinfo():
tus = Location(32.2, -111, ZoneInfo('US/Arizona'), 700, 'Tucson')
def test_location_print_pytz():
tus = Location(32.2, -111, pytz.timezone('US/Arizona'), 700, 'Tucson')
expected_str = '\n'.join([
'Location: ',
' name: Tucson',
Expand Down Expand Up @@ -221,7 +215,7 @@ def test_from_tmy_3():
from pvlib.iotools import read_tmy3
data, meta = read_tmy3(TMY3_TESTFILE, map_variables=True)
loc = Location.from_tmy(meta, data)
assert loc.name != ""
assert loc.name is not None
assert loc.altitude != 0
assert loc.tz != 'UTC'
assert_frame_equal(loc.weather, data)
Expand All @@ -232,7 +226,7 @@ def test_from_tmy_2():
from pvlib.iotools import read_tmy2
data, meta = read_tmy2(TMY2_TESTFILE)
loc = Location.from_tmy(meta, data)
assert loc.name != ""
assert loc.name is not None
assert loc.altitude != 0
assert loc.tz != 'UTC'
assert_frame_equal(loc.weather, data)
Expand All @@ -243,7 +237,7 @@ def test_from_epw():
from pvlib.iotools import read_epw
data, meta = read_epw(epw_testfile)
loc = Location.from_epw(meta, data)
assert loc.name != ""
assert loc.name is not None
assert loc.altitude != 0
assert loc.tz != 'UTC'
assert_frame_equal(loc.weather, data)
Expand Down
Loading
Loading
0