diff --git a/xarray/coding/cftimeindex.py b/xarray/coding/cftimeindex.py index 341ecfed262..75a1fc9bd1a 100644 --- a/xarray/coding/cftimeindex.py +++ b/xarray/coding/cftimeindex.py @@ -389,8 +389,5 @@ 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)