Skip to content

Commit 238146d

Browse files
authored
fix ForecastModel.get_data handling of timezones (pvlib#1285)
* fix ForecastModel.get_data handling of timezones * update pr number
1 parent f318c1c commit 238146d

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ Enhancements
127127
for retrieving and reading BSRN solar radiation data files.
128128
(:pull:`1254`, :pull:`1145`, :issue:`1015`)
129129
* Add :func:`~pvlib.iotools.get_cams`,
130-
:func:`~pvlib.iotools.parse_cams`, and
130+
:func:`~pvlib.iotools.parse_cams`, and
131131
:func:`~pvlib.iotools.read_cams`
132132
for retrieving, parsing, and reading CAMS Radiation and McClear time-series
133133
files. (:pull:`1175`)
@@ -179,9 +179,9 @@ Enhancements
179179
Bug fixes
180180
~~~~~~~~~
181181
* Corrected an error in :py:func:`~pvlib.irradiance.perez` where the horizon
182-
irradiance component was prevented from taking negative values. Negative
183-
values are intentional according to the original publication. Changes in
184-
output are expected to be small and primarily occur at low irradiance
182+
irradiance component was prevented from taking negative values. Negative
183+
values are intentional according to the original publication. Changes in
184+
output are expected to be small and primarily occur at low irradiance
185185
conditions.
186186
(:issue:`1238`, :pull:`1239`)
187187
* Pass weather data to solar position calculations in
@@ -205,7 +205,9 @@ Bug fixes
205205
* Changed deprecated use of ``.astype()`` to ``.view()`` in :py:mod:`~pvlib.solarposition`.
206206
(:pull:`1256`, :issue:`1261`, :pull:`1262`)
207207
* Fix :py:func:`~pvlib.tracking.singleaxis` AOI wrong when sun behind module.
208-
(:pull:`1273`, :issue:`1221`)
208+
(:pull:`1273`, :issue:`1221`)
209+
* Fix :py:meth:`~pvlib.forecast.ForecastModel.get_data` failure to correct for
210+
non-UTC timezones. (:issue:`1237`, :pull:`1285`)
209211

210212
Testing
211213
~~~~~~~

pvlib/forecast.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,12 @@ def set_query_time_range(self, start, end):
183183
self.end = pd.Timestamp(end)
184184
if self.start.tz is None or self.end.tz is None:
185185
raise TypeError('start and end must be tz-localized')
186-
self.query.time_range(self.start, self.end)
186+
# don't assume that siphon or the server can handle anything other
187+
# than UTC
188+
self.query.time_range(
189+
self.start.tz_convert('UTC'),
190+
self.end.tz_convert('UTC')
191+
)
187192

188193
def set_query_latlon(self):
189194
'''
@@ -412,10 +417,14 @@ def set_time(self, time):
412417
-------
413418
pandas.DatetimeIndex
414419
'''
420+
# np.masked_array with elements like real_datetime(2021, 8, 17, 16, 0)
421+
# and dtype=object
415422
times = num2date(time[:].squeeze(), time.units,
416423
only_use_cftime_datetimes=False,
417424
only_use_python_datetimes=True)
418-
self.time = pd.DatetimeIndex(pd.Series(times), tz=self.location.tz)
425+
# convert to pandas, localize to UTC, convert to desired timezone
426+
self.time = pd.DatetimeIndex(
427+
times, tz='UTC').tz_convert(self.location.tz)
419428

420429
def cloud_cover_to_ghi_linear(self, cloud_cover, ghi_clear, offset=35,
421430
**kwargs):

0 commit comments

Comments
 (0)