diff --git a/docs/sphinx/source/whatsnew/v0.16.0.rst b/docs/sphinx/source/whatsnew/v0.16.0.rst index 6d62b9e1c6..d850d511de 100644 --- a/docs/sphinx/source/whatsnew/v0.16.0.rst +++ b/docs/sphinx/source/whatsnew/v0.16.0.rst @@ -19,6 +19,10 @@ Deprecations Bug fixes ~~~~~~~~~ +* Fixed a ``TypeError`` in :py:class:`~pvlib.modelchain.ModelChain` when + ``dc_ohmic_model="dc_ohms_from_percent"`` is used with a single-Array system + and the weather/irradiance input is passed as a length-1 list or tuple. + (:issue:`2829`) Enhancements @@ -48,3 +52,4 @@ Maintenance Contributors ~~~~~~~~~~~~ * Carolina Crespo (:ghuser:`cbcrespo`) +* Sai Asish Y (:ghuser:`SAY-5`) diff --git a/pvlib/modelchain.py b/pvlib/modelchain.py index 45374bd6fa..d50c74596c 100644 --- a/pvlib/modelchain.py +++ b/pvlib/modelchain.py @@ -1032,8 +1032,8 @@ def dc_ohms_from_percent(self): method. Uses a `dc_ohmic_percent` parameter in the `losses_parameters` of the PVsystem. """ - Rw = self.system.dc_ohms_from_percent() if isinstance(self.results.dc, tuple): + Rw = self.system.dc_ohms_from_percent(unwrap=False) self.results.dc_ohmic_losses = tuple( pvsystem.dc_ohmic_losses(Rw, df['i_mp']) for Rw, df in zip(Rw, self.results.dc) @@ -1041,6 +1041,7 @@ def dc_ohms_from_percent(self): for df, loss in zip(self.results.dc, self.results.dc_ohmic_losses): df['p_mp'] = df['p_mp'] - loss else: + Rw = self.system.dc_ohms_from_percent() self.results.dc_ohmic_losses = pvsystem.dc_ohmic_losses( Rw, self.results.dc['i_mp'] ) diff --git a/tests/test_modelchain.py b/tests/test_modelchain.py index 9ea804f014..c0db414cc5 100644 --- a/tests/test_modelchain.py +++ b/tests/test_modelchain.py @@ -1642,6 +1642,28 @@ def test_dc_ohmic_model_ohms_from_percent(cec_dc_snl_ac_system, assert isinstance(mc.results.dc_ohmic_losses, tuple) +@pytest.mark.parametrize("input_type", [tuple, list]) +def test_dc_ohmic_model_ohms_from_percent_single_array_list_input( + cec_dc_snl_ac_system, location, weather, total_irrad, input_type): + # GH 2829: a single-Array system given list/tuple input stores + # results.dc as a tuple, so dc_ohms_from_percent must not unwrap Rw + for array in cec_dc_snl_ac_system.arrays: + array.array_losses_parameters = dict(dc_ohmic_percent=3) + + data = weather.copy() + data[['poa_global', 'poa_diffuse', 'poa_direct']] = total_irrad + data['effective_irradiance'] = data['poa_global'] + + mc = ModelChain(cec_dc_snl_ac_system, location, + aoi_model='no_loss', + spectral_model='no_loss', + dc_ohmic_model='dc_ohms_from_percent') + mc.run_model_from_effective_irradiance(input_type((data,))) + + assert isinstance(mc.results.dc_ohmic_losses, tuple) + assert len(mc.results.dc_ohmic_losses) == 1 + + def test_dc_ohmic_model_no_dc_ohmic_loss(cec_dc_snl_ac_system, location, weather,