Skip to content

Commit d6d1492

Browse files
authored
numpy 1.16 compatibility (#644)
* fix issues with scalars and xfail * whatsnew
1 parent 5d2a6c8 commit d6d1492

File tree

7 files changed

+9
-5
lines changed

7 files changed

+9
-5
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ Bug fixes
7676
* Fix error in ``pvlib.spa`` when using Python 3.7 on some platforms.
7777
* Fix error in :func:`pvlib.irradiance._delta_kt_prime_dirint` (:issue:`637`). The error affects
7878
the first and last values of DNI calculated by the function :func:`pvlib.irradiance.dirint`
79+
* Fix errors on Python 2.7 and Numpy 1.6. (:issue:`642`)
80+
* Replace deprecated `np.asscalar` with `array.item()`. (:issue:`642`)
7981

8082

8183
Testing

pvlib/irradiance.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,7 @@ def perez(surface_tilt, surface_azimuth, dhi, dni, dni_extra,
11311131
# sense for small zenith angles, but...) these values will
11321132
# eventually be used as indicies for coeffecient look ups
11331133
ebin = np.digitize(eps, (0., 1.065, 1.23, 1.5, 1.95, 2.8, 4.5, 6.2))
1134+
ebin = np.array(ebin) # GH 642
11341135
ebin[np.isnan(eps)] = 0
11351136

11361137
# correct for 0 indexing in coeffecient lookup

pvlib/singlediode.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ def _lambertw_v_from_i(resistance_shunt, resistance_series, nNsVth, current,
465465
I[idx_p] * Rs[idx_p] - a[idx_p] * lambertwterm
466466

467467
if output_is_scalar:
468-
return np.asscalar(V)
468+
return V.item()
469469
else:
470470
return V
471471

@@ -528,7 +528,7 @@ def _lambertw_i_from_v(resistance_shunt, resistance_series, nNsVth, voltage,
528528
a[idx_p] / Rs[idx_p]) * lambertwterm
529529

530530
if output_is_scalar:
531-
return np.asscalar(I)
531+
return I.item()
532532
else:
533533
return I
534534

pvlib/spa.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1419,7 +1419,7 @@ def calculate_deltat(year, month):
14191419

14201420
-20+32*((y-1820)/100)**2, deltat)
14211421

1422-
deltat = np.asscalar(deltat) if np.isscalar(year) & np.isscalar(month)\
1422+
deltat = deltat.item() if np.isscalar(year) & np.isscalar(month)\
14231423
else deltat
14241424

14251425
return deltat

pvlib/test/test_irradiance.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,8 @@ def test_perez_scalar():
273273
out = irradiance.perez(40, 180, 118.45831879, 939.95469881,
274274
1321.1655834833093, 10.56413562, 144.76567754,
275275
1.01688136)
276+
# this will fail. out is ndarry with ndim == 0. fix in future version.
277+
# assert np.isscalar(out)
276278
assert_allclose(out, 109.084332)
277279

278280

pvlib/test/test_solarposition.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,6 @@ def test_get_solarposition_altitude(altitude, expected, golden):
541541
pytest.param(
542542
None, 'nrel_numba',
543543
marks=[pytest.mark.xfail(
544-
raises=ValueError,
545544
reason='spa.calculate_deltat not implemented for numba yet')]),
546545
(67.0, 'nrel_numba')
547546
])

pvlib/tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def _scalar_out(input):
212212
else: #
213213
# works if it's a 1 length array and
214214
# will throw a ValueError otherwise
215-
output = np.asscalar(input)
215+
output = input.item()
216216

217217
return output
218218

0 commit comments

Comments
 (0)