diff --git a/pvlib/pvsystem.py b/pvlib/pvsystem.py index 6894facc4a..edd1149244 100644 --- a/pvlib/pvsystem.py +++ b/pvlib/pvsystem.py @@ -98,8 +98,9 @@ class PVSystem: arrays : iterable of Array, optional List of arrays that are part of the system. If not specified a single array is created from the other parameters (e.g. - `surface_tilt`, `surface_azimuth`). If `arrays` is specified - the following parameters are ignored: + `surface_tilt`, `surface_azimuth`). Must contain at least one Array, + if length of arrays is 0 a ValueError is raised. If `arrays` is + specified the following parameters are ignored: - `surface_tilt` - `surface_azimuth` @@ -173,6 +174,11 @@ class PVSystem: Arbitrary keyword arguments. Included for compatibility, but not used. + Raises + ------ + ValueError + If `arrays` is not None and has length 0. + See also -------- pvlib.location.Location @@ -210,6 +216,12 @@ def __init__(self, racking_model, array_losses_parameters, ),) + elif len(arrays) == 0: + raise ValueError("PVSystem must have at least one Array. " + "If you want to create a PVSystem instance " + "with a single Array pass `arrays=None` and pass " + "values directly to PVSystem attributes, e.g., " + "`surface_tilt=30`") else: self.arrays = tuple(arrays) diff --git a/pvlib/tests/test_pvsystem.py b/pvlib/tests/test_pvsystem.py index 0a4125dd5b..2c2a64d672 100644 --- a/pvlib/tests/test_pvsystem.py +++ b/pvlib/tests/test_pvsystem.py @@ -2084,6 +2084,12 @@ def test_PVSystem_num_arrays(): assert system_two.num_arrays == 2 +def test_PVSystem_at_least_one_array(): + with pytest.raises(ValueError, + match="PVSystem must have at least one Array"): + pvsystem.PVSystem(arrays=[]) + + def test_combine_loss_factors(): test_index = pd.date_range(start='1990/01/01T12:00', periods=365, freq='D') loss_1 = pd.Series(.10, index=test_index)