From 38203da97fdf069eb5157ac4ffc26dbc1c9fc5c9 Mon Sep 17 00:00:00 2001 From: Zebedee Nicholls Date: Thu, 18 Mar 2021 15:30:00 +1100 Subject: [PATCH 1/4] Add failing test of future only handling --- xarray/tests/test_coding_times.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/xarray/tests/test_coding_times.py b/xarray/tests/test_coding_times.py index eda32d31148..ad0ff9249fc 100644 --- a/xarray/tests/test_coding_times.py +++ b/xarray/tests/test_coding_times.py @@ -79,6 +79,9 @@ (0, "microseconds since 2000-01-01T00:00:00"), (np.int32(788961600), "seconds since 1981-01-01"), # GH2002 (12300 + np.arange(5), "hour since 1680-01-01 00:00:00.500000"), + (164375, "days since 1850-01-01 00:00:00"), + (164374.5, "days since 1850-01-01 00:00:00"), + ([164374.5, 168360.5], "days since 1850-01-01 00:00:00"), ] _CF_DATETIME_TESTS = [ num_dates_units + (calendar,) From 4f481afa789176ab6986a67c244a5031a968cfb8 Mon Sep 17 00:00:00 2001 From: Zebedee Nicholls Date: Thu, 18 Mar 2021 15:48:21 +1100 Subject: [PATCH 2/4] Re-introduce fix removed in #4684 --- xarray/coding/times.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/xarray/coding/times.py b/xarray/coding/times.py index a1822393dc1..ff42e4e8973 100644 --- a/xarray/coding/times.py +++ b/xarray/coding/times.py @@ -181,6 +181,11 @@ def _decode_datetime_with_pandas(flat_num_dates, units, calendar): # strings, in which case we fall back to using cftime raise OutOfBoundsDatetime + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "invalid value encountered", RuntimeWarning) + pd.to_timedelta(flat_num_dates.min(), delta) + ref_date + pd.to_timedelta(flat_num_dates.max(), delta) + ref_date + # To avoid integer overflow when converting to nanosecond units for integer # dtypes smaller than np.int64 cast all integer-dtype arrays to np.int64 # (GH 2002). From 2274f8d34a70b61002a91361ebcb92b6b6ab2cec Mon Sep 17 00:00:00 2001 From: Zebedee Nicholls Date: Thu, 18 Mar 2021 23:01:54 +1100 Subject: [PATCH 3/4] whatsnew --- doc/whats-new.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index fbd2617b16f..09cdfbe7cfd 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -74,6 +74,7 @@ Deprecations Bug fixes ~~~~~~~~~ +- Ensure times after 2262 are correctly decoded and don't silently overflow. By `Zeb Nicholls `_. - Added support for `numpy.bool_` attributes in roundtrips using `h5netcdf` engine with `invalid_netcdf=True` [which casts `bool`s to `numpy.bool_`] (:issue:`4981`, :pull:`4986`). By `Victor Negîrneac `_. - Don't allow passing ``axis`` to :py:meth:`Dataset.reduce` methods (:issue:`3510`, :pull:`4940`). From 5c75f66ae670c06131a2bc3763d5bf13453b156f Mon Sep 17 00:00:00 2001 From: Zeb Nicholls Date: Fri, 19 Mar 2021 00:29:01 +1100 Subject: [PATCH 4/4] Update doc/whats-new.rst Co-authored-by: Spencer Clark --- doc/whats-new.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 09cdfbe7cfd..77d6296acac 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -74,7 +74,7 @@ Deprecations Bug fixes ~~~~~~~~~ -- Ensure times after 2262 are correctly decoded and don't silently overflow. By `Zeb Nicholls `_. +- Ensure standard calendar times encoded with large values (i.e. greater than approximately 292 years), can be decoded correctly without silently overflowing (:pull:`5050`). This was a regression in xarray 0.17.0. By `Zeb Nicholls `_. - Added support for `numpy.bool_` attributes in roundtrips using `h5netcdf` engine with `invalid_netcdf=True` [which casts `bool`s to `numpy.bool_`] (:issue:`4981`, :pull:`4986`). By `Victor Negîrneac `_. - Don't allow passing ``axis`` to :py:meth:`Dataset.reduce` methods (:issue:`3510`, :pull:`4940`).