From 1652b0db97d4f3480b41b56f033ec12f75b4b50b Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Tue, 25 Sep 2018 10:58:23 -0700 Subject: [PATCH 1/2] FIX: datetime64 now recognized if in a list --- lib/matplotlib/dates.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/matplotlib/dates.py b/lib/matplotlib/dates.py index a229e09f5e63..3b28818664b5 100644 --- a/lib/matplotlib/dates.py +++ b/lib/matplotlib/dates.py @@ -405,18 +405,19 @@ def date2num(d): Gregorian calendar is assumed; this is not universal practice. For details see the module docstring. """ - if hasattr(d, "values"): # this unpacks pandas series or dataframes... d = d.values - - if ((isinstance(d, np.ndarray) and np.issubdtype(d.dtype, np.datetime64)) - or isinstance(d, np.datetime64)): - return _dt64_to_ordinalf(d) if not np.iterable(d): + if (isinstance(d, np.datetime64) or (isinstance(d, np.ndarray) and + np.issubdtype(d.dtype, np.datetime64))): + return _dt64_to_ordinalf(d) return _to_ordinalf(d) + else: d = np.asarray(d) + if np.issubdtype(d.dtype, np.datetime64): + return _dt64_to_ordinalf(d) if not d.size: return d return _to_ordinalf_np_vectorized(d) From 86d3257ce5afc5b6bc60ccc7371ec0856b0f1ee1 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Tue, 25 Sep 2018 18:43:52 -0700 Subject: [PATCH 2/2] TST: test list datetime64 converts --- lib/matplotlib/tests/test_dates.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/matplotlib/tests/test_dates.py b/lib/matplotlib/tests/test_dates.py index db153be5ff97..da742c0236c9 100644 --- a/lib/matplotlib/tests/test_dates.py +++ b/lib/matplotlib/tests/test_dates.py @@ -641,3 +641,9 @@ def test_tz_utc(): def test_num2timedelta(x, tdelta): dt = mdates.num2timedelta(x) assert dt == tdelta + + +def test_datetime64_in_list(): + dt = [np.datetime64('2000-01-01'), np.datetime64('2001-01-01')] + dn = mdates.date2num(dt) + assert np.array_equal(dn, [730120., 730486.])