Skip to content

Commit 1746e21

Browse files
committed
Fix integer truncation in temperature.fuentes by forcing float dtype and update tests
1 parent 802dfc6 commit 1746e21

2 files changed

Lines changed: 49 additions & 2 deletions

File tree

pvlib/temperature.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import numpy as np
77
import pandas as pd
88
from pvlib.tools import sind
9-
from pvlib._deprecation import warn_deprecated
109
from pvlib.tools import _get_sample_intervals
1110
import scipy
1211
import scipy.constants
@@ -883,7 +882,7 @@ def fuentes(poa_global, temp_air, wind_speed, noct_installed, module_height=5,
883882
windmod_array = wind_speed * (module_height/wind_height)**0.2 + 1e-4
884883

885884
tmod0 = 293.15
886-
tmod_array = np.zeros_like(poa_global)
885+
tmod_array = np.zeros_like(poa_global, dtype=float)
887886

888887
iterator = zip(tamb_array, sun_array, windmod_array, tsky_array,
889888
timedelta_hours)

tests/test_temperature.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,3 +501,51 @@ def test_glm_repr():
501501
"'alpha': 0.9}")
502502

503503
assert glm.__repr__() == expected
504+
505+
506+
@pytest.mark.parametrize('tz', [None, 'Etc/GMT+5'])
507+
def test_fuentes_timezone(tz):
508+
index = pd.date_range('2019-01-01', freq='h', periods=3, tz=tz)
509+
510+
df = pd.DataFrame({'poa_global': 1000, 'temp_air': 20, 'wind_speed': 1},
511+
index)
512+
513+
out = temperature.fuentes(df['poa_global'], df['temp_air'],
514+
df['wind_speed'], noct_installed=45)
515+
516+
expected = pd.Series(
517+
[48.041843, 51.845471, 51.846428],
518+
index=index,
519+
name='tmod'
520+
)
521+
522+
assert_series_equal(out.round(6), expected.round(6))
523+
524+
525+
def test_fuentes_int_vs_float():
526+
"""Ensure integer and float inputs give identical results."""
527+
index = pd.date_range("2019-01-01", freq="h", periods=2)
528+
529+
inputs = pd.DataFrame({
530+
"poa_global": [1000, 500],
531+
"temp_air": [25, 25],
532+
"wind_speed": [1, 1],
533+
}, index=index)
534+
535+
result_int = temperature.fuentes(
536+
poa_global=inputs["poa_global"],
537+
temp_air=inputs["temp_air"],
538+
wind_speed=inputs["wind_speed"],
539+
noct_installed=45
540+
)
541+
542+
inputs_float = inputs.astype(float)
543+
544+
result_float = temperature.fuentes(
545+
poa_global=inputs_float["poa_global"],
546+
temp_air=inputs_float["temp_air"],
547+
wind_speed=inputs_float["wind_speed"],
548+
noct_installed=45
549+
)
550+
551+
assert_allclose(result_int.values, result_float.values)

0 commit comments

Comments
 (0)