Fix Fuentes int input truncation by forcing float dtype
Closes #2608
Summary
This PR fixes a dtype-dependent bug in pvlib.temperature.fuentes where integer poa_global inputs could lead to truncated module temperatures and slightly different results compared to float inputs with the same numeric values.
Changes
-
In
pvlib.temperature.fuentes:- Changed
tmod_array = np.zeros_like(poa_global)totmod_array = np.zeros_like(poa_global, dtype=float)so internal temperature calculations always use a float dtype.
- Changed
-
In
tests/test_temperature.py:- Added
test_fuentes_int_float_consistency, which callsfuenteswith both integer and floatpoa_globalseries (same values, datetime index) and asserts that the results match within floating-point tolerance.
- Added
Rationale
Previously, when poa_global was an integer Series, tmod_array was also integer, so intermediate temperatures such as 321.19 K were truncated to 321 when stored. Converting to Celsius (tmod_array - 273.15) produced a different value than for float inputs.
This change ensures that physically identical inputs (100 vs 100.0) produce identical Fuentes outputs.
Testing
-
pytest tests/test_temperature.py::test_fuentes -v -
pytest tests/test_temperature.py::test_fuentes_int_float_consistency -v
@kumaradityaapril please address the formatting issues identified by Flake8.
There are two tests that use the fuentes model that now fail, almost certainly because the expected values were computed with the fuentes function that was doing integer truncation. I think it's OK to update the expected values and use as many digits as needed to get the tests to pass with the default rtol and atol values, so we don't have to relax those tolerances.
Thanks for the review. I’ll address the Flake8 formatting issues and update the Fuentes-related tests.
For the tests that use the Fuentes model, I’ll recompute the expected values using the corrected fuentes implementation and update the hard-coded expectations (with sufficient precision) so that they pass with the default rtol and atol settings, without relaxing tolerances.