Skip to content

Commit

Permalink
Fix read_ecmwf_macc test failure for cftime>=1.6.0 (#1656)
Browse files Browse the repository at this point in the history
* use 'nearest' instead of 'before' and 'after'

* whatsnew
  • Loading branch information
kandersolar committed Feb 4, 2023
1 parent a19b528 commit faf27fe
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/sphinx/source/whatsnew/v0.9.5.rst
Expand Up @@ -25,6 +25,9 @@ Bug fixes
* Fixed incorrect mapping of requested parameters names when using the ``get_psm3``
function. Also fixed the random reordering of the dataframe columns.
(:issue:`1629`, :issue:`1647`, :pull:`1648`)
* When using ``utc_time_range`` with :py:func:`pvlib.iotools.read_ecmwf_macc`,
the time index subset is now selected with ``nearest`` instead of ``before``
and ``after`` for consistency with ``cftime>=1.6.0``. (:issue:`1609`, :pull:`1656`)


Testing
Expand Down Expand Up @@ -56,3 +59,4 @@ Contributors
* Mark Mikofski (:ghuser:`mikofski`)
* Anton Driesse (:ghuser:`adriesse`)
* Adam R. Jensen (:ghuser:`AdamRJensen`)
* Michael Deceglie (:ghuser:`mdeceglie`)
4 changes: 2 additions & 2 deletions pvlib/iotools/ecmwf_macc.py
Expand Up @@ -294,9 +294,9 @@ def read_ecmwf_macc(filename, latitude, longitude, utc_time_range=None):
nctime = ecmwf_macc.data['time']
if utc_time_range:
start_idx = netCDF4.date2index(
utc_time_range[0], nctime, select='before')
utc_time_range[0], nctime, select='nearest')
end_idx = netCDF4.date2index(
utc_time_range[-1], nctime, select='after')
utc_time_range[-1], nctime, select='nearest')
time_slice = slice(start_idx, end_idx + 1)
else:
time_slice = slice(0, ecmwf_macc.time_size)
Expand Down

0 comments on commit faf27fe

Please sign in to comment.