diff --git a/docs/sphinx/source/whatsnew/v0.8.1.rst b/docs/sphinx/source/whatsnew/v0.8.1.rst index 50e01401f5..59f9878006 100644 --- a/docs/sphinx/source/whatsnew/v0.8.1.rst +++ b/docs/sphinx/source/whatsnew/v0.8.1.rst @@ -17,7 +17,8 @@ Enhancements Bug fixes ~~~~~~~~~ - +* Fix issue with :py:func:`pvlib.temperature.fuentes` with timezone-aware + inputs. (:issue:`1071`, :pull:`1072`) Testing ~~~~~~~ diff --git a/pvlib/temperature.py b/pvlib/temperature.py index 1d98736b4f..1dd32fecf8 100644 --- a/pvlib/temperature.py +++ b/pvlib/temperature.py @@ -599,8 +599,9 @@ 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 - timedelta_hours = np.append([timedelta_hours[0]], timedelta_hours) + timedelta_seconds = poa_global.index.to_series().diff().dt.total_seconds() + timedelta_hours = timedelta_seconds / 3600 + timedelta_hours.iloc[0] = timedelta_hours.iloc[1] tamb_array = temp_air + 273.15 sun_array = poa_global * absorp diff --git a/pvlib/tests/test_temperature.py b/pvlib/tests/test_temperature.py index 245c5d2807..411adcfcca 100644 --- a/pvlib/tests/test_temperature.py +++ b/pvlib/tests/test_temperature.py @@ -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'))