From 6cd5dbaebd7d3bb9d5458b6297eaa614f1275f0c Mon Sep 17 00:00:00 2001 From: Spencer Clark Date: Thu, 4 Oct 2018 16:56:06 -0400 Subject: [PATCH 1/2] Make _parse_array_of_cftime_strings more robust --- xarray/coding/cftimeindex.py | 8 +++----- xarray/tests/test_cftimeindex.py | 8 +++++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/xarray/coding/cftimeindex.py b/xarray/coding/cftimeindex.py index 341ecfed262..68da61656c1 100644 --- a/xarray/coding/cftimeindex.py +++ b/xarray/coding/cftimeindex.py @@ -389,8 +389,6 @@ def _parse_array_of_cftime_strings(strings, date_type): ------- np.array """ - if strings.ndim == 0: - return np.array(_parse_iso8601_without_reso(date_type, strings.item())) - else: - return np.array([_parse_iso8601_without_reso(date_type, s) - for s in strings]) + return np.array([_parse_iso8601_without_reso(date_type, s) + for s in strings.ravel()]).reshape(strings.shape) + diff --git a/xarray/tests/test_cftimeindex.py b/xarray/tests/test_cftimeindex.py index a558ab9a784..33bf2cbce0d 100644 --- a/xarray/tests/test_cftimeindex.py +++ b/xarray/tests/test_cftimeindex.py @@ -689,9 +689,11 @@ def test_cftimeindex_shift_invalid_freq(): def test_parse_array_of_cftime_strings(): from cftime import DatetimeNoLeap - strings = np.array(['2000-01-01', '2000-01-02']) - expected = np.array([DatetimeNoLeap(2000, 1, 1), - DatetimeNoLeap(2000, 1, 2)]) + strings = np.array([['2000-01-01', '2000-01-02'], + ['2000-01-03', '2000-01-04']]) + expected = np.array( + [[DatetimeNoLeap(2000, 1, 1), DatetimeNoLeap(2000, 1, 2)], + [DatetimeNoLeap(2000, 1, 3), DatetimeNoLeap(2000, 1, 4)]]) result = _parse_array_of_cftime_strings(strings, DatetimeNoLeap) np.testing.assert_array_equal(result, expected) From 346d2e1b0d9851cf25519bec97fcd621eea81292 Mon Sep 17 00:00:00 2001 From: Spencer Clark Date: Thu, 4 Oct 2018 17:04:15 -0400 Subject: [PATCH 2/2] lint --- xarray/coding/cftimeindex.py | 1 - 1 file changed, 1 deletion(-) diff --git a/xarray/coding/cftimeindex.py b/xarray/coding/cftimeindex.py index 68da61656c1..75a1fc9bd1a 100644 --- a/xarray/coding/cftimeindex.py +++ b/xarray/coding/cftimeindex.py @@ -391,4 +391,3 @@ def _parse_array_of_cftime_strings(strings, date_type): """ return np.array([_parse_iso8601_without_reso(date_type, s) for s in strings.ravel()]).reshape(strings.shape) -