Skip to content

Commit c4a2b4b

Browse files
matsuobashocwhansekandersolar
authored
Fix error message modelchain.infer_temperature_model error to be more informative (#1977)
* Update error message in infer_temperature_model * Updated whats new rst doc * Minor wording update to bug fix description about error message update * Fix ValuerError message formatting in infer_temperature_model to address linter issues * Capitalize beginning of error message in modelchain.infer_temperature_model Co-authored-by: Cliff Hansen <[email protected]> * Update pvlib/modelchain.py Spelling error correction in error message Co-authored-by: Kevin Anderson <[email protected]> * Update test_inconsistent_array_params and test_temperature_model_not_specified with the correct error message from infer_tempertaure_model --------- Co-authored-by: Cliff Hansen <[email protected]> Co-authored-by: Kevin Anderson <[email protected]>
1 parent e5fa03c commit c4a2b4b

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

docs/sphinx/source/whatsnew/v0.10.4.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ Bug fixes
3333
``temperature_model_parameters`` are specified on the passed ``system`` instead of on its ``arrays``. (:issue:`1759`).
3434
* :py:func:`pvlib.irradiance.ghi_from_poa_driesse_2023` now correctly makes use
3535
of the ``xtol`` argument. Previously, it was ignored. (:issue:`1970`, :pull:`1971`)
36+
* :py:class:`~pvlib.modelchain.ModelChain.infer_temperature_model` now raises a more useful error when
37+
the temperature model cannot be inferred (:issue:`1946`)
3638

3739
Testing
3840
~~~~~~~
@@ -55,7 +57,7 @@ Contributors
5557
* Echedey Luis (:ghuser:`echedey-ls`)
5658
* Kevin Anderson (:ghuser:`kandersolar`)
5759
* Cliff Hansen (:ghuser:`cwhanse`)
58-
* :ghuser:`matsuobasho`
60+
* Roma Koulikov (:ghuser:`matsuobasho`)
5961
* Adam R. Jensen (:ghuser:`AdamRJensen`)
6062
* Kevin Anderson (:ghuser:`kandersolar`)
6163
* Peter Dudfield (:ghuser:`peterdudfield`)

pvlib/modelchain.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -1128,11 +1128,15 @@ def infer_temperature_model(self):
11281128
elif {'noct', 'module_efficiency'} <= params:
11291129
return self.noct_sam_temp
11301130
else:
1131-
raise ValueError(f'could not infer temperature model from '
1132-
f'system.temperature_model_parameters. Check '
1133-
f'that all Arrays in system.arrays have '
1134-
f'parameters for the same temperature model. '
1135-
f'Common temperature model parameters: {params}.')
1131+
raise ValueError('Could not infer temperature model from '
1132+
'ModelChain.system. '
1133+
'If Arrays are used to construct the PVSystem, '
1134+
'check that all Arrays in '
1135+
'ModelChain.system.arrays '
1136+
'have parameters for the same temperature model. '
1137+
'If Arrays are not used, check that the PVSystem '
1138+
'attributes `racking_model` and `module_type` '
1139+
'are valid.')
11361140

11371141
def _set_celltemp(self, model):
11381142
"""Set self.results.cell_temperature using the given cell

pvlib/tests/test_modelchain.py

+4-9
Original file line numberDiff line numberDiff line change
@@ -1306,17 +1306,15 @@ def test_temperature_model_inconsistent(location, sapm_dc_snl_ac_system):
13061306

13071307

13081308
def test_temperature_model_not_specified():
1309-
# GH 1759 -- ensure correct error is raised when temperature model params
1310-
# are specified on the PVSystem instead of the Arrays
13111309
location = Location(latitude=32.2, longitude=-110.9)
13121310
arrays = [pvsystem.Array(pvsystem.FixedMount(),
13131311
module_parameters={'pdc0': 1, 'gamma_pdc': 0})]
13141312
system = pvsystem.PVSystem(arrays,
13151313
temperature_model_parameters={'u0': 1, 'u1': 1},
13161314
inverter_parameters={'pdc0': 1})
13171315
with pytest.raises(ValueError,
1318-
match='could not infer temperature model '
1319-
'from system.temperature_model_parameters'):
1316+
match='Could not infer temperature model from '
1317+
'ModelChain.system.'):
13201318
_ = ModelChain(system, location,
13211319
aoi_model='no_loss', spectral_model='no_loss')
13221320

@@ -1957,11 +1955,8 @@ def test_inconsistent_array_params(location,
19571955
cec_module_params):
19581956
module_error = ".* selected for the DC model but one or more Arrays are " \
19591957
"missing one or more required parameters"
1960-
temperature_error = "could not infer temperature model from " \
1961-
r"system\.temperature_model_parameters\. Check " \
1962-
r"that all Arrays in system\.arrays have " \
1963-
r"parameters for the same temperature model\. " \
1964-
r"Common temperature model parameters: .*"
1958+
temperature_error = 'Could not infer temperature model from ' \
1959+
'ModelChain.system. '
19651960
different_module_system = pvsystem.PVSystem(
19661961
arrays=[
19671962
pvsystem.Array(

0 commit comments

Comments
 (0)