From c4a2b4bdb99216dbf1bf1dd58c7156f25c0e7458 Mon Sep 17 00:00:00 2001 From: matsuobasho Date: Mon, 11 Mar 2024 13:06:14 -0400 Subject: [PATCH] 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 * Update pvlib/modelchain.py Spelling error correction in error message Co-authored-by: Kevin Anderson * 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 Co-authored-by: Kevin Anderson --- docs/sphinx/source/whatsnew/v0.10.4.rst | 4 +++- pvlib/modelchain.py | 14 +++++++++----- pvlib/tests/test_modelchain.py | 13 ++++--------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/docs/sphinx/source/whatsnew/v0.10.4.rst b/docs/sphinx/source/whatsnew/v0.10.4.rst index 30abfbfe2a..7dbf7d7d6d 100644 --- a/docs/sphinx/source/whatsnew/v0.10.4.rst +++ b/docs/sphinx/source/whatsnew/v0.10.4.rst @@ -33,6 +33,8 @@ Bug fixes ``temperature_model_parameters`` are specified on the passed ``system`` instead of on its ``arrays``. (:issue:`1759`). * :py:func:`pvlib.irradiance.ghi_from_poa_driesse_2023` now correctly makes use of the ``xtol`` argument. Previously, it was ignored. (:issue:`1970`, :pull:`1971`) +* :py:class:`~pvlib.modelchain.ModelChain.infer_temperature_model` now raises a more useful error when + the temperature model cannot be inferred (:issue:`1946`) Testing ~~~~~~~ @@ -55,7 +57,7 @@ Contributors * Echedey Luis (:ghuser:`echedey-ls`) * Kevin Anderson (:ghuser:`kandersolar`) * Cliff Hansen (:ghuser:`cwhanse`) -* :ghuser:`matsuobasho` +* Roma Koulikov (:ghuser:`matsuobasho`) * Adam R. Jensen (:ghuser:`AdamRJensen`) * Kevin Anderson (:ghuser:`kandersolar`) * Peter Dudfield (:ghuser:`peterdudfield`) diff --git a/pvlib/modelchain.py b/pvlib/modelchain.py index d65f262c23..95bbad4531 100644 --- a/pvlib/modelchain.py +++ b/pvlib/modelchain.py @@ -1128,11 +1128,15 @@ def infer_temperature_model(self): elif {'noct', 'module_efficiency'} <= params: return self.noct_sam_temp else: - raise ValueError(f'could not infer temperature model from ' - f'system.temperature_model_parameters. Check ' - f'that all Arrays in system.arrays have ' - f'parameters for the same temperature model. ' - f'Common temperature model parameters: {params}.') + raise ValueError('Could not infer temperature model from ' + 'ModelChain.system. ' + 'If Arrays are used to construct the PVSystem, ' + 'check that all Arrays in ' + 'ModelChain.system.arrays ' + 'have parameters for the same temperature model. ' + 'If Arrays are not used, check that the PVSystem ' + 'attributes `racking_model` and `module_type` ' + 'are valid.') def _set_celltemp(self, model): """Set self.results.cell_temperature using the given cell diff --git a/pvlib/tests/test_modelchain.py b/pvlib/tests/test_modelchain.py index 72c349c8e6..9fd4660602 100644 --- a/pvlib/tests/test_modelchain.py +++ b/pvlib/tests/test_modelchain.py @@ -1306,8 +1306,6 @@ def test_temperature_model_inconsistent(location, sapm_dc_snl_ac_system): def test_temperature_model_not_specified(): - # GH 1759 -- ensure correct error is raised when temperature model params - # are specified on the PVSystem instead of the Arrays location = Location(latitude=32.2, longitude=-110.9) arrays = [pvsystem.Array(pvsystem.FixedMount(), module_parameters={'pdc0': 1, 'gamma_pdc': 0})] @@ -1315,8 +1313,8 @@ def test_temperature_model_not_specified(): temperature_model_parameters={'u0': 1, 'u1': 1}, inverter_parameters={'pdc0': 1}) with pytest.raises(ValueError, - match='could not infer temperature model ' - 'from system.temperature_model_parameters'): + match='Could not infer temperature model from ' + 'ModelChain.system.'): _ = ModelChain(system, location, aoi_model='no_loss', spectral_model='no_loss') @@ -1957,11 +1955,8 @@ def test_inconsistent_array_params(location, cec_module_params): module_error = ".* selected for the DC model but one or more Arrays are " \ "missing one or more required parameters" - temperature_error = "could not infer temperature model from " \ - r"system\.temperature_model_parameters\. Check " \ - r"that all Arrays in system\.arrays have " \ - r"parameters for the same temperature model\. " \ - r"Common temperature model parameters: .*" + temperature_error = 'Could not infer temperature model from ' \ + 'ModelChain.system. ' different_module_system = pvsystem.PVSystem( arrays=[ pvsystem.Array(