Skip to content

Commit 446fa9e

Browse files
committed
add test to check for verbose yet graceful failure of v_from_i
* check size of all args * return value error if this_size > size and size > 1
1 parent ff8cc0b commit 446fa9e

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

pvlib/pvsystem.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2268,7 +2268,8 @@ def i_from_v(resistance_shunt, resistance_series, nNsVth, voltage,
22682268
# wrap it so it returns nan
22692269
i_from_v_fun = singlediode_methods.returns_nan()(i_from_v_fun)
22702270
# find the right size and shape for returns
2271-
args = (voltage, photocurrent, resistance_shunt)
2271+
args = (voltage, photocurrent, saturation_current, resistance_series,
2272+
resistance_shunt, nNsVth)
22722273
size = 0
22732274
shape = None
22742275
for n, arg in enumerate(args):
@@ -2288,15 +2289,18 @@ def i_from_v(resistance_shunt, resistance_series, nNsVth, voltage,
22882289
size = this_size
22892290
if this_shape is not None:
22902291
shape = this_shape
2292+
else:
2293+
msg = ('Argument: "%s" is different size from other arguments'
2294+
' (%d > %d). All arguments must be the same size or'
2295+
' scalar.') % (arg, this_size, size)
2296+
raise ValueError(msg)
22912297
if size <= 1:
2292-
I = i_from_v_fun(voltage, photocurrent, saturation_current,
2293-
resistance_series, resistance_shunt, nNsVth)
2298+
I = i_from_v_fun(*args)
22942299
if shape is not None:
22952300
I = np.tile(I, shape)
22962301
else:
22972302
vecfun = np.vectorize(i_from_v_fun)
2298-
I = vecfun(voltage, photocurrent, saturation_current,
2299-
resistance_series, resistance_shunt, nNsVth)
2303+
I = vecfun(*args)
23002304
if np.isnan(I).any() and size <= 1:
23012305
I = np.repeat(I, size)
23022306
if shape is not None:

pvlib/test/test_pvsystem.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,12 @@ def test_PVSystem_i_from_v():
625625
assert_allclose(output, 3.0, atol=1e-5)
626626

627627

628+
@requires_scipy
629+
@pytest.raises(ValueError)
630+
def test_i_from_v_size():
631+
pvsystem.i_from_v(20, [0.1] * 2, 0.5, [7.5] * 3, 6.0e-7, 7.0)
632+
633+
628634
@requires_scipy
629635
def test_mpp_floats():
630636
"""test mpp"""

0 commit comments

Comments
 (0)