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 all commits
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
16 changes: 14 additions & 2 deletions pvlib/pvsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

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