diff --git a/xarray/conventions.py b/xarray/conventions.py index ef7705eb6d7..4a81ebc07d2 100644 --- a/xarray/conventions.py +++ b/xarray/conventions.py @@ -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) diff --git a/xarray/test/test_conventions.py b/xarray/test/test_conventions.py index be328eb0406..265b2a93b0f 100644 --- a/xarray/test/test_conventions.py +++ b/xarray/test/test_conventions.py @@ -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):