pvlib-python icon indicating copy to clipboard operation
pvlib-python copied to clipboard

Fix Fuentes int input truncation by forcing float dtype

Open kumaradityaapril opened this issue 1 month ago • 2 comments

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) to tmod_array = np.zeros_like(poa_global, dtype=float) so internal temperature calculations always use a float dtype.
  • In tests/test_temperature.py:

    • Added test_fuentes_int_float_consistency, which calls fuentes with both integer and float poa_global series (same values, datetime index) and asserts that the results match within floating-point tolerance.

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 avatar Dec 10 '25 17:12 kumaradityaapril

@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.

cwhanse avatar Dec 10 '25 17:12 cwhanse

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.

kumaradityaapril avatar Dec 11 '25 08:12 kumaradityaapril