Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/sphinx/source/whatsnew/v0.8.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ Enhancements

Bug fixes
~~~~~~~~~

* Fix issue with :py:func:`pvlib.temperature.fuentes` with timezone-aware
inputs. (:issue:`1071`, :pull:`1072`)

Testing
~~~~~~~
Expand Down
3 changes: 2 additions & 1 deletion pvlib/temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,8 @@ def fuentes(poa_global, temp_air, wind_speed, noct_installed, module_height=5,
# n.b. the way Fuentes calculates the first timedelta makes it seem like
# the value doesn't matter -- rather than recreate it here, just assume
# it's the same as the second timedelta:
timedelta_hours = np.diff(poa_global.index).astype(float) / 1e9 / 60 / 60
timedeltas = (poa_global.index[1:] - poa_global.index[:-1])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this equivalent to poa_global.index.to_series().diff().total_seconds() / 3600?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type is different (series vs index), but that doesn't matter in this context. With timedelta_hours.iloc[0] = timedelta_hours.iloc[1], the two are equivalent, so I'll use yours 👍

timedelta_hours = timedeltas.total_seconds() / 60 / 60
timedelta_hours = np.append([timedelta_hours[0]], timedelta_hours)

tamb_array = temp_air + 273.15
Expand Down
14 changes: 14 additions & 0 deletions pvlib/tests/test_temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,17 @@ def test_fuentes(filename, inoct):
night_difference = expected_tcell[is_night] - actual_tcell[is_night]
assert night_difference.max() < 6
assert night_difference.min() > 0


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

assert_series_equal(out, pd.Series([47.85, 50.85, 50.85], index=index,
name='tmod'))