Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
spencerkclark committed May 14, 2018
1 parent ebe0dd0 commit 8ff7c36
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 6 additions & 1 deletion xarray/coding/times.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,12 @@ def infer_datetime_units(dates):
else:
reference_date = dates[0] if len(dates) > 0 else '1970-01-01'
reference_date = format_cftime_datetime(reference_date)
unique_timedeltas = np.unique(np.diff(dates)).astype('timedelta64[ns]')
unique_timedeltas = np.unique(np.diff(dates))
if unique_timedeltas.dtype == np.dtype('O'):
# Convert to np.timedelta64 objects one at a time to work around a
# NumPy casting bug (GH 2127)
unique_timedeltas = np.array([np.timedelta64(delta, 'ns')
for delta in unique_timedeltas])
units = _infer_time_units_from_diff(unique_timedeltas)
return '%s since %s' % (units, reference_date)

Expand Down
3 changes: 3 additions & 0 deletions xarray/tests/test_coding_times.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,9 @@ def test_infer_cftime_datetime_units():
'seconds since 1900-01-01 00:00:00.000000'),
([date_type(1900, 1, 1),
date_type(1900, 1, 2, 0, 0, 0, 5)],
'days since 1900-01-01 00:00:00.000000'),
([date_type(1900, 1, 1), date_type(1900, 1, 8),
date_type(1900, 1, 16)],
'days since 1900-01-01 00:00:00.000000')]:
assert expected == coding.times.infer_datetime_units(dates)

Expand Down

0 comments on commit 8ff7c36

Please sign in to comment.