Skip to content
Open
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
5 changes: 5 additions & 0 deletions docs/sphinx/source/whatsnew/v0.16.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -48,3 +52,4 @@ Maintenance
Contributors
~~~~~~~~~~~~
* Carolina Crespo (:ghuser:`cbcrespo`)
* Sai Asish Y (:ghuser:`SAY-5`)
3 changes: 2 additions & 1 deletion pvlib/modelchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -1032,15 +1032,16 @@ 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)
)
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']
)
Expand Down
22 changes: 22 additions & 0 deletions tests/test_modelchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading