Skip to content

Commit

Permalink
Bug in DecodedCFDatetimeArray (pydata#1112)
Browse files Browse the repository at this point in the history
* Bug in DecodedCFDatetimeArray

* simpler unittest

* mini nit
  • Loading branch information
fmaussion authored and shoyer committed Nov 13, 2016
1 parent 95bca62 commit 0ed1e2c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions xarray/conventions.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,8 @@ def __init__(self, array, units, calendar=None):
# Verify that at least the first and last date can be decoded
# successfully. Otherwise, tracebacks end up swallowed by
# Dataset.__repr__ when users try to view their lazily decoded array.
example_value = np.concatenate([first_n_items(array, 1),
last_item(array), [0]])
example_value = np.concatenate([first_n_items(array, 1) or [0],
last_item(array) or [0]])

try:
result = decode_cf_datetime(example_value, units, calendar)
Expand Down
6 changes: 6 additions & 0 deletions xarray/test/test_conventions.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,12 @@ def test_dataset_repr_with_netcdf4_datetimes(self):
ds = decode_cf(Dataset({'time': ('time', [0, 1], attrs)}))
self.assertIn('(time) datetime64[ns]', repr(ds))

# this should not throw a warning (GH1111)
with warnings.catch_warnings():
warnings.filterwarnings('error')
conventions.DecodedCFDatetimeArray(np.asarray([722624]),
"days since 0001-01-01")


class TestNativeEndiannessArray(TestCase):
def test(self):
Expand Down

0 comments on commit 0ed1e2c

Please sign in to comment.