10000 dates: address review comments · matplotlib/matplotlib@45ff942 · GitHub
[go: up one dir, main page]

Skip to content

Commit 45ff942

Browse files
committed
dates: address review comments
1 parent 4a4c216 commit 45ff942

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

lib/matplotlib/dates.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@
9696
<../gallery/ticks_and_spines/date_demo_rrule.html>`_.
9797
9898
* :class:`AutoDateLocator`: On autoscale, this class picks the best
99-
:class:`DateLocator` to set the view limits and the tick
99+
:class:`DateLocator` (e.g., :class:`RRuleLocator`)
100+
to set the view limits and the tick
100101
locations. If called with ``interval_multiples=True`` it will
101102
make ticks line up with sensible multiples of the tick intervals. E.g.
102103
if the interval is 4 hours, it will pick hours 0, 4, 8, etc as ticks.
@@ -290,22 +291,21 @@ def _from_ordinalf(x, tz=None):
290291

291292
remainder = float(x) - ix
292293

293-
# Round to the nearest microsecond.
294-
dt += datetime.timedelta(
295-
microseconds=int(round(remainder * MUSECONDS_PER_DAY)))
296-
297-
# Compensate for rounding errors
298-
if x > 30 * 365:
299-
# Since the input date `x` float is unable to preserve
300-
# microsecond precision of time representation in non-antique
301-
# years, the resulting datetime is rounded to the nearest
302-
# multiple of `musec_prec`. A value of 20 is appropriate for
303-
# current dates.
304-
musec_prec = 20
305-
musec = datetime.timedelta(
306-
microseconds=int(round(
307-
dt.microsecond / float(musec_prec)) * musec_prec))
308-
dt = dt.replace(microsecond=0) + musec
294+
# Since the input date `x` float is unable to preserve microsecond
295+
# precision of time representation in non-antique years, the
296+
# resulting datetime is rounded to the nearest multiple of
297+
# `musec_prec`. A value of 20 is appropriate for current dates.
298+
musec_prec = 20
299+
remainder_musec = int(round(remainder * MUSECONDS_PER_DAY /
300+
float(musec_prec)) * musec_prec)
301+
302+
# For people trying to plot with full microsecond precision, enable
303+
# an early-year workaround
304+
if x < 30 * 365:
305+
remainder_musec = int(round(remainder * MUSECONDS_PER_DAY))
306+
307+
# add hours, minutes, seconds, microseconds
308+
dt += datetime.timedelta(microseconds=remainder_musec)
309309

310310
return dt.astimezone(tz)
311311

0 commit comments

Comments
 (0)
0