Skip to content

MNT: simplify AutoDateFormatter #11770

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 8, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 3 additions & 30 deletions pandas/tseries/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
from pandas.tseries.frequencies import FreqGroup
from pandas.tseries.period import Period, PeriodIndex

from matplotlib.dates import (HOURS_PER_DAY, MINUTES_PER_DAY,
SEC_PER_DAY, MUSECONDS_PER_DAY)


def register():
units.registry[lib.Timestamp] = DatetimeConverter()
Expand Down Expand Up @@ -136,11 +139,6 @@ def get_datevalue(date, freq):
return None
raise ValueError("Unrecognizable date '%s'" % date)

HOURS_PER_DAY = 24.
MINUTES_PER_DAY = 60. * HOURS_PER_DAY
SECONDS_PER_DAY = 60. * MINUTES_PER_DAY
MUSECONDS_PER_DAY = 1e6 * SECONDS_PER_DAY


def _dt_to_float_ordinal(dt):
"""
Expand Down Expand Up @@ -222,31 +220,6 @@ def __init__(self, locator, tz=None, defaultfmt='%Y-%m-%d'):
# matplotlib.dates._UTC has no _utcoffset called by pandas
if self._tz is dates.UTC:
self._tz._utcoffset = self._tz.utcoffset(None)
self.scaled = {
365.0: '%Y',
30.: '%b %Y',
1.0: '%b %d %Y',
1. / 24.: '%H:%M:%S',
1. / 24. / 3600. / 1000.: '%H:%M:%S.%f'
}

def _get_fmt(self, x):

scale = float(self._locator._get_unit())

fmt = self.defaultfmt

for k in sorted(self.scaled):
if k >= scale:
fmt = self.scaled[k]
break

return fmt

def __call__(self, x, pos=0):
fmt = self._get_fmt(x)
self._formatter = dates.DateFormatter(fmt, self._tz)
return self._formatter(x, pos)


class PandasAutoDateLocator(dates.AutoDateLocator):
Expand Down