From 9d44e637db603417be2716f6c1902527085ec0c5 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Tue, 10 May 2016 19:47:02 -0400 Subject: [PATCH] BUG: mpl fix to AutoDatFromatter to fix second/us-second formatters revert part of #11770 xref: https://github.com/matplotlib/matplotlib/issues/6365 closes #13131 The mistake in #11770 was missing that pandas had a 1/us not 1/s scaled bucket. --- doc/source/whatsnew/v0.18.2.txt | 1 + pandas/tseries/converter.py | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/doc/source/whatsnew/v0.18.2.txt b/doc/source/whatsnew/v0.18.2.txt index 251fb4c139b04..907ca6f185e0a 100644 --- a/doc/source/whatsnew/v0.18.2.txt +++ b/doc/source/whatsnew/v0.18.2.txt @@ -141,6 +141,7 @@ Bug Fixes - Bug in ``SparseDataFrame`` in which ``axis=None`` did not default to ``axis=0`` (:issue:`13048`) - Bug in ``SparseSeries`` and ``SparseDataFrame`` creation with ``object`` dtype may raise ``TypeError`` (:issue:`11633`) - Bug when passing a not-default-indexed ``Series`` as ``xerr`` or ``yerr`` in ``.plot()`` (:issue:`11858`) +- Bug in matplotlib ``AutoDataFormatter``; this restores the second scaled formatting and re-adds micro-second scaled formatting (:issue:`13131`) - Bug in ``.groupby(..).resample(..)`` when the same object is called multiple times (:issue:`13174`) diff --git a/pandas/tseries/converter.py b/pandas/tseries/converter.py index 8ccfdfa05e9b5..78b185ae8cf31 100644 --- a/pandas/tseries/converter.py +++ b/pandas/tseries/converter.py @@ -23,6 +23,24 @@ from pandas.tseries.frequencies import FreqGroup from pandas.tseries.period import Period, PeriodIndex +# constants +HOURS_PER_DAY = 24. +MIN_PER_HOUR = 60. +SEC_PER_MIN = 60. + +SEC_PER_HOUR = SEC_PER_MIN * MIN_PER_HOUR +SEC_PER_DAY = SEC_PER_HOUR * HOURS_PER_DAY + +MUSEC_PER_DAY = 1e6 * SEC_PER_DAY + + +def _mpl_le_2_0_0(): + try: + import matplotlib + return matplotlib.compare_versions('2.0.0', matplotlib.__version__) + except ImportError: + return False + def register(): units.registry[lib.Timestamp] = DatetimeConverter() @@ -221,6 +239,13 @@ def __init__(self, locator, tz=None, defaultfmt='%Y-%m-%d'): if self._tz is dates.UTC: self._tz._utcoffset = self._tz.utcoffset(None) + # For mpl > 2.0 the format strings are controlled via rcparams + # so do not mess with them. For mpl < 2.0 change the second + # break point and add a musec break point + if _mpl_le_2_0_0(): + self.scaled[1. / SEC_PER_DAY] = '%H:%M:%S' + self.scaled[1. / MUSEC_PER_DAY] = '%H:%M:%S.%f' + class PandasAutoDateLocator(dates.AutoDateLocator):