Skip to content

Commit 0326b6f

Browse files
authored
Raise ValueError if PVSystem constructed with 0 Arrays (#1224)
1 parent 943663a commit 0326b6f

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

pvlib/pvsystem.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,9 @@ class PVSystem:
9898
arrays : iterable of Array, optional
9999
List of arrays that are part of the system. If not specified
100100
a single array is created from the other parameters (e.g.
101-
`surface_tilt`, `surface_azimuth`). If `arrays` is specified
102-
the following parameters are ignored:
101+
`surface_tilt`, `surface_azimuth`). Must contain at least one Array,
102+
if length of arrays is 0 a ValueError is raised. If `arrays` is
103+
specified the following parameters are ignored:
103104
104105
- `surface_tilt`
105106
- `surface_azimuth`
@@ -173,6 +174,11 @@ class PVSystem:
173174
Arbitrary keyword arguments.
174175
Included for compatibility, but not used.
175176
177+
Raises
178+
------
179+
ValueError
180+
If `arrays` is not None and has length 0.
181+
176182
See also
177183
--------
178184
pvlib.location.Location
@@ -210,6 +216,12 @@ def __init__(self,
210216
racking_model,
211217
array_losses_parameters,
212218
),)
219+
elif len(arrays) == 0:
220+
raise ValueError("PVSystem must have at least one Array. "
221+
"If you want to create a PVSystem instance "
222+
"with a single Array pass `arrays=None` and pass "
223+
"values directly to PVSystem attributes, e.g., "
224+
"`surface_tilt=30`")
213225
else:
214226
self.arrays = tuple(arrays)
215227

pvlib/tests/test_pvsystem.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2067,6 +2067,12 @@ def test_PVSystem_num_arrays():
20672067
assert system_two.num_arrays == 2
20682068

20692069

2070+
def test_PVSystem_at_least_one_array():
2071+
with pytest.raises(ValueError,
2072+
match="PVSystem must have at least one Array"):
2073+
pvsystem.PVSystem(arrays=[])
2074+
2075+
20702076
def test_combine_loss_factors():
20712077
test_index = pd.date_range(start='1990/01/01T12:00', periods=365, freq='D')
20722078
loss_1 = pd.Series(.10, index=test_index)

0 commit comments

Comments
 (0)