Skip to content

Commit bb0e0b4

Browse files
wholmgrencwhanse
authored andcommitted
fix pvwatts_ac exception and return value when called with pdc=0s (#676)
* assert what the pvwatts_ac(0) output should be * fix it
1 parent ee31db1 commit bb0e0b4

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ Enhancements
2424
Bug fixes
2525
~~~~~~~~~
2626
* Compatibility with pandas 0.24 deprecations. (:issue:`659`)
27+
* pvwatts_ac raised ZeroDivisionError when called with scalar pdc=0
28+
and a RuntimeWarning for array(0) input. Now correctly returns 0s
29+
of the appropriate type. (:issue:`675`)
2730

2831

2932
Testing

pvlib/pvsystem.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2967,8 +2967,15 @@ def pvwatts_ac(pdc, pdc0, eta_inv_nom=0.96, eta_inv_ref=0.9637):
29672967
pac0 = eta_inv_nom * pdc0
29682968
zeta = pdc / pdc0
29692969

2970+
# arrays to help avoid divide by 0 for scalar and array
2971+
eta = np.zeros_like(pdc, dtype=float)
2972+
pdc_neq_0 = ~np.equal(pdc, 0)
2973+
29702974
# eta < 0 if zeta < 0.006. pac is forced to be >= 0 below. GH 541
2971-
eta = eta_inv_nom / eta_inv_ref * (-0.0162*zeta - 0.0059/zeta + 0.9858)
2975+
eta = eta_inv_nom / eta_inv_ref * (
2976+
- 0.0162*zeta
2977+
- np.divide(0.0059, zeta, out=eta, where=pdc_neq_0)
2978+
+ 0.9858)
29722979

29732980
pac = eta * pdc
29742981
pac = np.minimum(pac0, pac)

pvlib/test/test_pvsystem.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,6 +1366,10 @@ def test_pvwatts_ac_scalars():
13661366
expected = 85.58556604752516
13671367
out = pvsystem.pvwatts_ac(90, 100, 0.95)
13681368
assert_allclose(out, expected)
1369+
# GH 675
1370+
expected = 0.
1371+
out = pvsystem.pvwatts_ac(0., 100)
1372+
assert_allclose(out, expected)
13691373

13701374

13711375
def test_pvwatts_ac_possible_negative():
@@ -1378,19 +1382,20 @@ def test_pvwatts_ac_possible_negative():
13781382

13791383
@needs_numpy_1_10
13801384
def test_pvwatts_ac_arrays():
1381-
pdc = np.array([[np.nan], [50], [100]])
1385+
pdc = np.array([[np.nan], [0], [50], [100]])
13821386
pdc0 = 100
13831387
expected = np.array([[nan],
1388+
[0.],
13841389
[47.60843624],
13851390
[95.]])
13861391
out = pvsystem.pvwatts_ac(pdc, pdc0, 0.95)
13871392
assert_allclose(out, expected, equal_nan=True)
13881393

13891394

13901395
def test_pvwatts_ac_series():
1391-
pdc = pd.Series([np.nan, 50, 100])
1396+
pdc = pd.Series([np.nan, 0, 50, 100])
13921397
pdc0 = 100
1393-
expected = pd.Series(np.array([ nan, 47.608436, 95. ]))
1398+
expected = pd.Series(np.array([nan, 0., 47.608436, 95.]))
13941399
out = pvsystem.pvwatts_ac(pdc, pdc0, 0.95)
13951400
assert_series_equal(expected, out)
13961401

0 commit comments

Comments
 (0)