Skip to content

Commit f8b9c04

Browse files
authored
Fix fuentes error for tz-aware inputs (#1072)
* swap out timedelta calculation; add tz test * whatsnew * suggestion from review
1 parent c24bab0 commit f8b9c04

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

docs/sphinx/source/whatsnew/v0.8.1.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ Enhancements
1717

1818
Bug fixes
1919
~~~~~~~~~
20-
20+
* Fix issue with :py:func:`pvlib.temperature.fuentes` with timezone-aware
21+
inputs. (:issue:`1071`, :pull:`1072`)
2122

2223
Testing
2324
~~~~~~~

pvlib/temperature.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -599,8 +599,9 @@ def fuentes(poa_global, temp_air, wind_speed, noct_installed, module_height=5,
599599
# n.b. the way Fuentes calculates the first timedelta makes it seem like
600600
# the value doesn't matter -- rather than recreate it here, just assume
601601
# it's the same as the second timedelta:
602-
timedelta_hours = np.diff(poa_global.index).astype(float) / 1e9 / 60 / 60
603-
timedelta_hours = np.append([timedelta_hours[0]], timedelta_hours)
602+
timedelta_seconds = poa_global.index.to_series().diff().dt.total_seconds()
603+
timedelta_hours = timedelta_seconds / 3600
604+
timedelta_hours.iloc[0] = timedelta_hours.iloc[1]
604605

605606
tamb_array = temp_air + 273.15
606607
sun_array = poa_global * absorp

pvlib/tests/test_temperature.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,17 @@ def test_fuentes(filename, inoct):
190190
night_difference = expected_tcell[is_night] - actual_tcell[is_night]
191191
assert night_difference.max() < 6
192192
assert night_difference.min() > 0
193+
194+
195+
@pytest.mark.parametrize('tz', [None, 'Etc/GMT+5'])
196+
def test_fuentes_timezone(tz):
197+
index = pd.date_range('2019-01-01', freq='h', periods=3, tz=tz)
198+
199+
df = pd.DataFrame({'poa_global': 1000, 'temp_air': 20, 'wind_speed': 1},
200+
index)
201+
202+
out = temperature.fuentes(df['poa_global'], df['temp_air'],
203+
df['wind_speed'], noct_installed=45)
204+
205+
assert_series_equal(out, pd.Series([47.85, 50.85, 50.85], index=index,
206+
name='tmod'))

0 commit comments

Comments
 (0)