From 1746e216697304e7ea7fea0d407ecd9d8b4033e1 Mon Sep 17 00:00:00 2001 From: Chirag3841 Date: Thu, 5 Mar 2026 20:25:29 +0530 Subject: [PATCH] Fix integer truncation in temperature.fuentes by forcing float dtype and update tests --- pvlib/temperature.py | 3 +-- tests/test_temperature.py | 48 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/pvlib/temperature.py b/pvlib/temperature.py index cb487ee77b..55222c0fb1 100644 --- a/pvlib/temperature.py +++ b/pvlib/temperature.py @@ -6,7 +6,6 @@ import numpy as np import pandas as pd from pvlib.tools import sind -from pvlib._deprecation import warn_deprecated from pvlib.tools import _get_sample_intervals import scipy import scipy.constants @@ -883,7 +882,7 @@ def fuentes(poa_global, temp_air, wind_speed, noct_installed, module_height=5, windmod_array = wind_speed * (module_height/wind_height)**0.2 + 1e-4 tmod0 = 293.15 - tmod_array = np.zeros_like(poa_global) + tmod_array = np.zeros_like(poa_global, dtype=float) iterator = zip(tamb_array, sun_array, windmod_array, tsky_array, timedelta_hours) diff --git a/tests/test_temperature.py b/tests/test_temperature.py index e482df6214..e45dbe2b1b 100644 --- a/tests/test_temperature.py +++ b/tests/test_temperature.py @@ -501,3 +501,51 @@ def test_glm_repr(): "'alpha': 0.9}") assert glm.__repr__() == expected + + +@pytest.mark.parametrize('tz', [None, 'Etc/GMT+5']) +def test_fuentes_timezone(tz): + index = pd.date_range('2019-01-01', freq='h', periods=3, tz=tz) + + df = pd.DataFrame({'poa_global': 1000, 'temp_air': 20, 'wind_speed': 1}, + index) + + out = temperature.fuentes(df['poa_global'], df['temp_air'], + df['wind_speed'], noct_installed=45) + + expected = pd.Series( + [48.041843, 51.845471, 51.846428], + index=index, + name='tmod' + ) + + assert_series_equal(out.round(6), expected.round(6)) + + +def test_fuentes_int_vs_float(): + """Ensure integer and float inputs give identical results.""" + index = pd.date_range("2019-01-01", freq="h", periods=2) + + inputs = pd.DataFrame({ + "poa_global": [1000, 500], + "temp_air": [25, 25], + "wind_speed": [1, 1], + }, index=index) + + result_int = temperature.fuentes( + poa_global=inputs["poa_global"], + temp_air=inputs["temp_air"], + wind_speed=inputs["wind_speed"], + noct_installed=45 + ) + + inputs_float = inputs.astype(float) + + result_float = temperature.fuentes( + poa_global=inputs_float["poa_global"], + temp_air=inputs_float["temp_air"], + wind_speed=inputs_float["wind_speed"], + noct_installed=45 + ) + + assert_allclose(result_int.values, result_float.values) \ No newline at end of file