Skip to content

Raise ValueError if PVSystem constructed with 0 Arrays #1224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 17, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion pvlib/pvsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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)

Expand Down
6 changes: 6 additions & 0 deletions pvlib/tests/test_pvsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down