From e2add9442071d49e60de479e85268e05eba78075 Mon Sep 17 00:00:00 2001 From: Will Vining Date: Mon, 10 May 2021 09:29:14 -0600 Subject: [PATCH 1/4] Raise ValueError if PVSystem constructed with 0 Arrays Provides a useful error message directing users to the solution they are most likely to want (construct a PVSystem with an arbitrary default Array). --- pvlib/pvsystem.py | 8 +++++++- pvlib/tests/test_pvsystem.py | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pvlib/pvsystem.py b/pvlib/pvsystem.py index 6894facc4a..c366b1f977 100644 --- a/pvlib/pvsystem.py +++ b/pvlib/pvsystem.py @@ -98,7 +98,8 @@ 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 + `surface_tilt`, `surface_azimuth`). Must contain at least one Array, + if empty a ValueError is raised. If `arrays` is specified the following parameters are ignored: - `surface_tilt` @@ -210,6 +211,11 @@ 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 arbitrary default Array pass " + "`arrays=None`.") 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) From 6fca2aefbd14b1b8c61226c90d12bb73b3c121b9 Mon Sep 17 00:00:00 2001 From: Will Vining Date: Mon, 17 May 2021 07:03:37 -0600 Subject: [PATCH 2/4] Reword description of `arrays` param to PVSystem --- pvlib/pvsystem.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pvlib/pvsystem.py b/pvlib/pvsystem.py index c366b1f977..53c3479ba6 100644 --- a/pvlib/pvsystem.py +++ b/pvlib/pvsystem.py @@ -99,8 +99,8 @@ class PVSystem: 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`). Must contain at least one Array, - if empty a ValueError is raised. If `arrays` is specified - the following parameters are ignored: + if length of arrays is 0 a ValueError is raised. If `arrays` is + specified the following parameters are ignored: - `surface_tilt` - `surface_azimuth` From 9ffc3aa0266bef334be0d776c83ce4edf09ffd2d Mon Sep 17 00:00:00 2001 From: Will Vining Date: Mon, 17 May 2021 07:05:47 -0600 Subject: [PATCH 3/4] Reword ValueError raised when arrays is empty --- pvlib/pvsystem.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pvlib/pvsystem.py b/pvlib/pvsystem.py index 53c3479ba6..ac47a294fd 100644 --- a/pvlib/pvsystem.py +++ b/pvlib/pvsystem.py @@ -214,8 +214,9 @@ def __init__(self, elif len(arrays) == 0: raise ValueError("PVSystem must have at least one Array. " "If you want to create a PVSystem instance " - "with a single arbitrary default Array pass " - "`arrays=None`.") + "with a single Array pass `arrays=None` and pass " + "values directly to PVSystem attributes, e.g., " + "`surface_tilt=30`") else: self.arrays = tuple(arrays) From 18458944cf5fef6c0972ab87d3341d34ff8ee7fc Mon Sep 17 00:00:00 2001 From: Will Vining Date: Mon, 17 May 2021 07:23:00 -0600 Subject: [PATCH 4/4] Add Raises section to PVSystem docstring --- pvlib/pvsystem.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pvlib/pvsystem.py b/pvlib/pvsystem.py index ac47a294fd..edd1149244 100644 --- a/pvlib/pvsystem.py +++ b/pvlib/pvsystem.py @@ -174,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