Skip to content

Commit

Permalink
BUG: mpl fix to AutoDatFromatter to fix second/us-second formatters
Browse files Browse the repository at this point in the history
revert part of #11770
xref: matplotlib/matplotlib#6365

closes #13131

The mistake in #11770 was missing that pandas had a 1/us not 1/s
scaled bucket.
  • Loading branch information
tacaswell authored and jreback committed May 20, 2016
1 parent 72164a8 commit 9d44e63
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.18.2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
25 changes: 25 additions & 0 deletions pandas/tseries/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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):

Expand Down

0 comments on commit 9d44e63

Please sign in to comment.