Skip to content

Commit 0ed1e2c

Browse files
fmaussionshoyer
authored andcommitted
Bug in DecodedCFDatetimeArray (#1112)
* Bug in DecodedCFDatetimeArray * simpler unittest * mini nit
1 parent 95bca62 commit 0ed1e2c

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

xarray/conventions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,8 @@ def __init__(self, array, units, calendar=None):
382382
# Verify that at least the first and last date can be decoded
383383
# successfully. Otherwise, tracebacks end up swallowed by
384384
# Dataset.__repr__ when users try to view their lazily decoded array.
385-
example_value = np.concatenate([first_n_items(array, 1),
386-
last_item(array), [0]])
385+
example_value = np.concatenate([first_n_items(array, 1) or [0],
386+
last_item(array) or [0]])
387387

388388
try:
389389
result = decode_cf_datetime(example_value, units, calendar)

xarray/test/test_conventions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,12 @@ def test_dataset_repr_with_netcdf4_datetimes(self):
494494
ds = decode_cf(Dataset({'time': ('time', [0, 1], attrs)}))
495495
self.assertIn('(time) datetime64[ns]', repr(ds))
496496

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

498504
class TestNativeEndiannessArray(TestCase):
499505
def test(self):

0 commit comments

Comments
 (0)