Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of abbreviated units like msec #3998

Merged
merged 2 commits into from
Apr 24, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ Bug fixes
- Fix bug causing :py:meth:`DataArray.interpolate_na` to always drop attributes,
and added `keep_attrs` argument. (:issue:`3968`)
By `Tom Nicholas <https://github.com/TomNicholas>`_.

- Fix bug in time parsing failing to fall back to cftime. This was causing time
variables with a time unit of `'msecs'` to fail to parse. (:pull:`3998`)
By `Ryan May <https://github.com/dopplershift>`_.

Documentation
~~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion xarray/coding/times.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def decode_cf_datetime(num_dates, units, calendar=None, use_cftime=None):
if use_cftime is None:
try:
dates = _decode_datetime_with_pandas(flat_num_dates, units, calendar)
except (OutOfBoundsDatetime, OverflowError):
except (KeyError, OutOfBoundsDatetime, OverflowError):
dates = _decode_datetime_with_cftime(
flat_num_dates.astype(np.float), units, calendar
)
Expand Down
12 changes: 12 additions & 0 deletions xarray/tests/test_coding_times.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,18 @@ def test_decode_360_day_calendar():
assert_array_equal(actual, expected)


@requires_cftime
def test_decode_abbreviation():
"""Test making sure we properly fall back to cftime on abbreviated units."""
import cftime

val = np.array([1586628000000.0])
units = "msecs since 1970-01-01T00:00:00Z"
actual = coding.times.decode_cf_datetime(val, units)
expected = coding.times.cftime_to_nptime(cftime.num2date(val, units))
assert_array_equal(actual, expected)


@arm_xfail
@requires_cftime
@pytest.mark.parametrize(
Expand Down