Skip to content

Commit 8668a61

Browse files
authored
Numpy 2.0 compatibility (#2027)
* change `np.Inf` to `np.inf` AttributeError: `np.Inf` was removed in the NumPy 2.0 release. Use `np.inf` instead. * change `np.NaN` to `np.nan` AttributeError: `np.NaN` was removed in the NumPy 2.0 release. Use `np.nan` instead. * fix np.uint8 range issue OverflowError: Python integer 450 out of bounds for uint8 * use `scipy.integrate.trapezoid` instead of `np.trapz` DeprecationWarning: `trapz` is deprecated. Use `trapezoid` instead, or one of the numerical integration functions in `scipy.integrate`. * advance minimum scipy from 1.5 to 1.6 for integrate.trapezoid * whatsnew PR number
1 parent 25ec296 commit 8668a61

19 files changed

+31
-25
lines changed

benchmarks/asv.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
"build": "",
118118
"numpy": "1.17.5",
119119
"pandas": "1.3.0",
120-
"scipy": "1.5.0",
120+
"scipy": "1.6.0",
121121
// Note: these don't have a minimum in setup.py
122122
"h5py": "3.1.0",
123123
"ephem": "3.7.6.0",

ci/requirements-py3.10.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ dependencies:
2121
- python=3.10
2222
- pytz
2323
- requests
24-
- scipy >= 1.5.0
24+
- scipy >= 1.6.0
2525
- statsmodels
2626
- pip:
2727
- nrel-pysam>=2.0

ci/requirements-py3.11.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ dependencies:
2121
- python=3.11
2222
- pytz
2323
- requests
24-
- scipy >= 1.5.0
24+
- scipy >= 1.6.0
2525
- statsmodels
2626
- pip:
2727
- nrel-pysam>=2.0

ci/requirements-py3.12.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ dependencies:
2121
- python=3.12
2222
- pytz
2323
- requests
24-
- scipy >= 1.5.0
24+
- scipy >= 1.6.0
2525
- statsmodels
2626
- pip:
2727
- nrel-pysam>=2.0

ci/requirements-py3.7-min.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ dependencies:
1616
- h5py==3.1.0
1717
- numpy==1.17.3
1818
- pandas==1.3.0
19-
- scipy==1.5.0
19+
- scipy==1.6.0
2020
- pytest-rerunfailures # conda version is >3.6
2121
- pytest-remotedata # conda package is 0.3.0, needs > 0.3.1
2222
- requests-mock

ci/requirements-py3.7.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ dependencies:
2121
- python=3.7
2222
- pytz
2323
- requests
24-
- scipy >= 1.5.0
24+
- scipy >= 1.6.0
2525
- statsmodels
2626
- pip:
2727
- nrel-pysam>=2.0

ci/requirements-py3.8.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ dependencies:
2121
- python=3.8
2222
- pytz
2323
- requests
24-
- scipy >= 1.5.0
24+
- scipy >= 1.6.0
2525
- statsmodels
2626
- pip:
2727
- nrel-pysam>=2.0

ci/requirements-py3.9.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ dependencies:
2121
- python=3.9
2222
- pytz
2323
- requests
24-
- scipy >= 1.5.0
24+
- scipy >= 1.6.0
2525
- statsmodels
2626
- pip:
2727
- nrel-pysam>=2.0

docs/sphinx/source/whatsnew/v0.10.5.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Documentation
3030

3131
Requirements
3232
~~~~~~~~~~~~
33+
* Minimum version of scipy advanced from 1.5.0 to 1.6.0. (:pull:`2027`)
3334

3435

3536
Contributors

pvlib/bifacial/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55
import numpy as np
66
from pvlib.tools import sind, cosd, tand
7+
from scipy.integrate import trapezoid
78

89

910
def _solar_projection_tangent(solar_zenith, solar_azimuth, surface_azimuth):
@@ -220,7 +221,7 @@ def vf_ground_sky_2d_integ(surface_tilt, gcr, height, pitch, max_rows=10,
220221
vf = vf_ground_sky_2d(r, gcr, z, pitch, height, max_rows)
221222
fz_sky[:, k] = vf[:, 0] # remove spurious rotation dimension
222223
# calculate the integrated view factor for all of the ground between rows
223-
return np.trapz(fz_sky, z, axis=0)
224+
return trapezoid(fz_sky, z, axis=0)
224225

225226

226227
def _vf_poly(surface_tilt, gcr, x, delta):

pvlib/iotools/srml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def read_srml(filename, map_variables=True):
9292
# Mask data marked with quality flag 99 (bad or missing data)
9393
for col in columns[::2]:
9494
missing = data[col + '_flag'] == 99
95-
data[col] = data[col].where(~(missing), np.NaN)
95+
data[col] = data[col].where(~(missing), np.nan)
9696
return data
9797

9898

pvlib/iotools/surfrad.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def read_surfrad(filename, map_variables=True):
152152

153153
data = _format_index(data)
154154
missing = data == -9999.9
155-
data = data.where(~missing, np.NaN)
155+
data = data.where(~missing, np.nan)
156156

157157
if map_variables:
158158
data.rename(columns=VARIABLE_MAP, inplace=True)

pvlib/location.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,10 @@ def lookup_altitude(latitude, longitude):
439439
# 255 is a special value that means nodata. Fallback to 0 if nodata.
440440
if alt == 255:
441441
return 0
442+
# convert from np.uint8 to float so that the following operations succeed
443+
alt = float(alt)
442444
# Altitude is encoded in 28 meter steps from -450 meters to 6561 meters
443445
# There are 0-254 possible altitudes, with 255 reserved for nodata.
444446
alt *= 28
445447
alt -= 450
446-
return float(alt)
448+
return alt

pvlib/pvsystem.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2536,7 +2536,7 @@ def singlediode(photocurrent, saturation_current, resistance_series,
25362536

25372537

25382538
def max_power_point(photocurrent, saturation_current, resistance_series,
2539-
resistance_shunt, nNsVth, d2mutau=0, NsVbi=np.Inf,
2539+
resistance_shunt, nNsVth, d2mutau=0, NsVbi=np.inf,
25402540
method='brentq'):
25412541
"""
25422542
Given the single diode equation coefficients, calculates the maximum power

pvlib/singlediode.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def estimate_voc(photocurrent, saturation_current, nNsVth):
5858

5959
def bishop88(diode_voltage, photocurrent, saturation_current,
6060
resistance_series, resistance_shunt, nNsVth, d2mutau=0,
61-
NsVbi=np.Inf, breakdown_factor=0., breakdown_voltage=-5.5,
61+
NsVbi=np.inf, breakdown_factor=0., breakdown_voltage=-5.5,
6262
breakdown_exp=3.28, gradients=False):
6363
r"""
6464
Explicit calculation of points on the IV curve described by the single
@@ -206,7 +206,7 @@ def bishop88(diode_voltage, photocurrent, saturation_current,
206206

207207
def bishop88_i_from_v(voltage, photocurrent, saturation_current,
208208
resistance_series, resistance_shunt, nNsVth,
209-
d2mutau=0, NsVbi=np.Inf, breakdown_factor=0.,
209+
d2mutau=0, NsVbi=np.inf, breakdown_factor=0.,
210210
breakdown_voltage=-5.5, breakdown_exp=3.28,
211211
method='newton', method_kwargs=None):
212212
"""
@@ -338,7 +338,7 @@ def vd_from_brent(voc, v, iph, isat, rs, rsh, gamma, d2mutau, NsVbi,
338338

339339
def bishop88_v_from_i(current, photocurrent, saturation_current,
340340
resistance_series, resistance_shunt, nNsVth,
341-
d2mutau=0, NsVbi=np.Inf, breakdown_factor=0.,
341+
d2mutau=0, NsVbi=np.inf, breakdown_factor=0.,
342342
breakdown_voltage=-5.5, breakdown_exp=3.28,
343343
method='newton', method_kwargs=None):
344344
"""
@@ -469,7 +469,7 @@ def vd_from_brent(voc, i, iph, isat, rs, rsh, gamma, d2mutau, NsVbi,
469469

470470

471471
def bishop88_mpp(photocurrent, saturation_current, resistance_series,
472-
resistance_shunt, nNsVth, d2mutau=0, NsVbi=np.Inf,
472+
resistance_shunt, nNsVth, d2mutau=0, NsVbi=np.inf,
473473
breakdown_factor=0., breakdown_voltage=-5.5,
474474
breakdown_exp=3.28, method='newton', method_kwargs=None):
475475
"""

pvlib/spectrum/mismatch.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import numpy as np
77
import pandas as pd
88
from scipy.interpolate import interp1d
9+
from scipy.integrate import trapezoid
910
import os
1011

1112
from warnings import warn
@@ -224,7 +225,7 @@ def calc_spectral_mismatch_field(sr, e_sun, e_ref=None):
224225

225226
# a helper function to make usable fraction calculations more readable
226227
def integrate(e):
227-
return np.trapz(e, x=e.T.index, axis=-1)
228+
return trapezoid(e, x=e.T.index, axis=-1)
228229

229230
# calculate usable fractions
230231
uf_sun = integrate(e_sun * sr_sun) / integrate(e_sun)

pvlib/tests/bifacial/test_utils.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from pvlib.bifacial import utils
77
from pvlib.shading import masking_angle, ground_angle
88
from pvlib.tools import cosd
9+
from scipy.integrate import trapezoid
910

1011

1112
@pytest.fixture
@@ -99,7 +100,7 @@ def test_vf_ground_sky_2d_integ(test_system_fixed_tilt, vectorize):
99100
vf_integ = utils.vf_ground_sky_2d_integ(
100101
ts['rotation'], ts['gcr'], ts['height'], ts['pitch'],
101102
max_rows=1, npoints=3, vectorize=vectorize)
102-
expected_vf_integ = np.trapz(vfs_gnd_sky, pts, axis=0)
103+
expected_vf_integ = trapezoid(vfs_gnd_sky, pts, axis=0)
103104
assert np.isclose(vf_integ, expected_vf_integ, rtol=0.1)
104105

105106

@@ -134,15 +135,15 @@ def test_vf_row_sky_2d_integ(test_system_fixed_tilt):
134135
x = np.arange(fx0[1], fx1[1], 1e-4)
135136
phi_y = masking_angle(ts['surface_tilt'], ts['gcr'], x)
136137
y = 0.5 * (1 + cosd(ts['surface_tilt'] + phi_y))
137-
y1 = np.trapz(y, x) / (fx1[1] - fx0[1])
138+
y1 = trapezoid(y, x) / (fx1[1] - fx0[1])
138139
expected = np.array([y0, y1])
139140
assert np.allclose(vf, expected, rtol=1e-3)
140141
# with defaults (0, 1)
141142
vf = utils.vf_row_sky_2d_integ(ts['surface_tilt'], ts['gcr'])
142143
x = np.arange(0, 1, 1e-4)
143144
phi_y = masking_angle(ts['surface_tilt'], ts['gcr'], x)
144145
y = 0.5 * (1 + cosd(ts['surface_tilt'] + phi_y))
145-
y1 = np.trapz(y, x) / (1 - 0)
146+
y1 = trapezoid(y, x) / (1 - 0)
146147
assert np.allclose(vf, y1, rtol=1e-3)
147148

148149

@@ -179,13 +180,13 @@ def test_vf_ground_2d_integ(test_system_fixed_tilt):
179180
x = np.arange(fx0[1], fx1[1], 1e-4)
180181
phi_y = ground_angle(ts['surface_tilt'], ts['gcr'], x)
181182
y = 0.5 * (1 - cosd(phi_y - ts['surface_tilt']))
182-
y1 = np.trapz(y, x) / (fx1[1] - fx0[1])
183+
y1 = trapezoid(y, x) / (fx1[1] - fx0[1])
183184
expected = np.array([y0, y1])
184185
assert np.allclose(vf, expected, rtol=1e-2)
185186
# with defaults (0, 1)
186187
vf = utils.vf_row_ground_2d_integ(ts['surface_tilt'], ts['gcr'], 0, 1)
187188
x = np.arange(0, 1, 1e-4)
188189
phi_y = ground_angle(ts['surface_tilt'], ts['gcr'], x)
189190
y = 0.5 * (1 - cosd(phi_y - ts['surface_tilt']))
190-
y1 = np.trapz(y, x) / (1 - 0)
191+
y1 = trapezoid(y, x) / (1 - 0)
191192
assert np.allclose(vf, y1, rtol=1e-2)

pvlib/tests/test_singlediode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ def test_pvsyst_recombination_loss(method, poa, temp_cell, expected, tol):
355355
# other conditions with breakdown model on and recombination model off
356356
(
357357
(1.e-4, -5.5, 3.28),
358-
(0., np.Inf),
358+
(0., np.inf),
359359
POA,
360360
TCELL,
361361
{

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ dependencies = [
1515
'pandas >= 1.3.0',
1616
'pytz',
1717
'requests',
18-
'scipy >= 1.5.0',
18+
'scipy >= 1.6.0',
1919
'h5py',
2020
'importlib-metadata; python_version < "3.8"',
2121
]

0 commit comments

Comments
 (0)