diff --git a/docs/sphinx/source/whatsnew/v0.10.2.rst b/docs/sphinx/source/whatsnew/v0.10.2.rst index d542c2c4c8..8da6e0d174 100644 --- a/docs/sphinx/source/whatsnew/v0.10.2.rst +++ b/docs/sphinx/source/whatsnew/v0.10.2.rst @@ -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 ~~~~~~~~~ diff --git a/pvlib/pvsystem.py b/pvlib/pvsystem.py index c277a778b3..35f39a1a80 100644 --- a/pvlib/pvsystem.py +++ b/pvlib/pvsystem.py @@ -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: @@ -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 " diff --git a/pvlib/tests/test_pvsystem.py b/pvlib/tests/test_pvsystem.py index b379dd41bc..dcacd280b3 100644 --- a/pvlib/tests/test_pvsystem.py +++ b/pvlib/tests/test_pvsystem.py @@ -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(): @@ -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)