Skip to content

Allow PVSystems to be created with single Arrays #1854

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 2 commits into from
Sep 13, 2023
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
3 changes: 3 additions & 0 deletions docs/sphinx/source/whatsnew/v0.10.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ Enhancements
* Added :py:func:`~pvlib.iam.interp` option as AOI losses model in
:py:class:`pvlib.modelchain.ModelChain` and
:py:class:`pvlib.pvsystem.PVSystem`. (:issue:`1742`, :pull:`1832`)
* :py:class:`~pvlib.pvsystem.PVSystem` objects with a single
:py:class:`~pvlib.pvsystem.Array` can now be created without wrapping the
``Array`` in a list first. (:issue:`1831`, :pull:`1854`)

Bug fixes
~~~~~~~~~
Expand Down
11 changes: 7 additions & 4 deletions pvlib/pvsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,11 @@ class PVSystem:

Parameters
----------
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`). Must contain at least one Array,
arrays : Array or iterable of Array, optional
An Array or 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 specified as a list, the list
must contain at least one Array;
if length of arrays is 0 a ValueError is raised. If `arrays` is
specified the following PVSystem parameters are ignored:

Expand Down Expand Up @@ -220,6 +221,8 @@ def __init__(self,
strings_per_inverter,
array_losses_parameters,
),)
elif isinstance(arrays, Array):
self.arrays = (arrays,)
elif len(arrays) == 0:
raise ValueError("PVSystem must have at least one Array. "
"If you want to create a PVSystem instance "
Expand Down
10 changes: 8 additions & 2 deletions pvlib/tests/test_pvsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -1887,8 +1887,6 @@ def test_PVSystem_multiple_array_creation():
assert pv_system.arrays[0].module_parameters == {}
assert pv_system.arrays[1].module_parameters == {'pdc0': 1}
assert pv_system.arrays == (array_one, array_two)
with pytest.raises(TypeError):
pvsystem.PVSystem(arrays=array_one)


def test_PVSystem_get_aoi():
Expand Down Expand Up @@ -2362,6 +2360,14 @@ def test_PVSystem_at_least_one_array():
pvsystem.PVSystem(arrays=[])


def test_PVSystem_single_array():
# GH 1831
single_array = pvsystem.Array(pvsystem.FixedMount())
system = pvsystem.PVSystem(arrays=single_array)
assert isinstance(system.arrays, tuple)
assert system.arrays[0] is single_array


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