8000 Fixed bug in serializing datetime scalars by shoyer · Pull Request #454 · pydata/xarray · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fixed bug in serializing datetime scalars #454

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

Merged
merged 1 commit into from
Jul 6, 2015
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
1 change: 1 addition & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Bug fixes

- :py:func:`~xray.open_dataset` and :py:func:`~xray.open_mfdataset` support
supplying chunks as a single integer.
- Fixed a bug in serializing scalar datetime variable to netCDF.

v0.5.1 (15 June 2015)
---------------------
Expand Down
4 changes: 2 additions & 2 deletions xray/conventions.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def infer_datetime_units(dates):
'hours', 'minutes' or 'seconds' (the first one that can evenly divide all
unique time deltas in `dates`)
"""
dates = pd.to_datetime(np.asarray(dates), box=False)
dates = pd.to_datetime(np.asarray(dates).ravel(), box=False)
unique_timedeltas = np.unique(np.diff(dates[pd.notnull(dates)]))
units = _infer_time_units_from_diff(unique_timedeltas)
return '%s since %s' % (units, pd.Timestamp(dates[0]))
Expand All @@ -192,7 +192,7 @@ def infer_timedelta_units(deltas):
{'days', 'hours', 'minutes' 'seconds'} (the first one that can evenly
divide all unique time deltas in `deltas`)
"""
deltas = pd.to_timedelta(np.asarray(deltas), box=False)
deltas = pd.to_timedelta(np.asarray(deltas).ravel(), box=False)
unique_timedeltas = np.unique(deltas[pd.notnull(deltas)])
units = _infer_time_units_from_diff(unique_timedeltas)
return units
Expand Down
4 changes: 2 additions & 2 deletions xray/test/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,13 @@ def test_roundtrip_string_data(self):

def test_roundtrip_datetime_data(self):
times = pd.to_datetime(['2000-01-01', '2000-01-02', 'NaT'])
expected = Dataset({'t': ('t', times)})
expected = Dataset({'t': ('t', times), 't0': times[0]})
with self.roundtrip(expected) as actual:
self.assertDatasetIdentical(expected, actual)

def test_roundtrip_timedelta_data(self):
time_deltas = pd.to_timedelta(['1h', '2h', 'NaT'])
expected = Dataset({'td': ('td', time_deltas)})
expected = Dataset({'td': ('td', time_deltas), 'td0': time_deltas[0]})
with self.roundtrip(expected) as actual:
self.assertDatasetIdentical(expected, actual)

Expand Down
0