From 59bbccb5cfc78ec1388f6d8729e72825b1c7860a Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Thu, 1 Mar 2018 09:28:17 -0800 Subject: [PATCH] ENH: autodecode pandas timestamps --- lib/matplotlib/dates.py | 4 ++++ lib/matplotlib/units.py | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/lib/matplotlib/dates.py b/lib/matplotlib/dates.py index b3fa42477ad2..0a3d8b3d477b 100644 --- a/lib/matplotlib/dates.py +++ b/lib/matplotlib/dates.py @@ -430,6 +430,10 @@ def date2num(d): 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) diff --git a/lib/matplotlib/units.py b/lib/matplotlib/units.py index 0df465430b46..cab3967189f7 100644 --- a/lib/matplotlib/units.py +++ b/lib/matplotlib/units.py @@ -160,6 +160,10 @@ def get_converter(self, x): if classx is not None: converter = self.get(classx) + if converter is None and hasattr(x, "values"): + # this unpacks pandas series or dataframes... + x = x.values + # If x is an array, look inside the array for data with units if isinstance(x, np.ndarray) and x.size: xravel = x.ravel()