@@ -268,7 +268,7 @@ def _dt64_to_ordinalf(d):
268
268
return dt
269
269
270
270
271
- def _from_ordinalf (x , tz = None , musec_prec = 20 ):
271
+ def _from_ordinalf (x , tz = None ):
272
272
"""
273
273
Convert Gregorian float of the date, preserving hours, minutes,
274
274
seconds and microseconds. Return value is a :class:`datetime`.
@@ -277,10 +277,6 @@ def _from_ordinalf(x, tz=None, musec_prec=20):
277
277
be the specified :class:`datetime` object corresponding to that time in
278
278
timezone `tz`, or if `tz` is `None`, in the timezone specified in
279
279
`rcParams['timezone']`.
280
-
281
- Since the input date `x` float is unable to preserve microsecond
282
- precision of time representation in non-antique years, the resulting
283
- datetime is rounded to the nearest multiple of `musec_prec`.
284
280
"""
285
281
if tz is None :
286
282
tz = _get_rc_timezone ()
@@ -295,7 +291,13 @@ def _from_ordinalf(x, tz=None, musec_prec=20):
295
291
microseconds = int (round (remainder * MUSECONDS_PER_DAY )))
296
292
297
293
# Compensate for rounding errors
298
- if musec_prec > 1 :
294
+ if x > 30 * 365 :
295
+ # Since the input date `x` float is unable to preserve
296
+ # microsecond precision of time representation in non-antique
297
+ # years, the resulting datetime is rounded to the nearest
298
+ # multiple of `musec_prec`. A value of 20 is appropriate for
299
+ # current dates.
300
+ musec_prec = 20
299
301
musec = datetime .timedelta (
300
302
microseconds = int (round (
301
303
dt .microsecond / float (musec_prec )) * musec_prec ))
@@ -451,7 +453,7 @@ def num2julian(n):
451
453
return n + JULIAN_OFFSET
452
454
453
455
454
- def num2date (x , tz = None , musec_prec = 20 ):
456
+ def num2date (x , tz = None ):
455
457
"""
456
458
Parameters
457
459
----------
@@ -460,8 +462,6 @@ def num2date(x, tz=None, musec_prec=20):
460
462
since 0001-01-01 00:00:00 UTC, plus one.
461
463
tz : string, optional
462
464
Timezone of *x* (defaults to rcparams TZ value).
463
- musec_prec : int, optional
464
- Microsecond precision of return value
465
465
466
466
Returns
467
467
-------
@@ -480,12 +480,12 @@ def num2date(x, tz=None, musec_prec=20):
480
480
if tz is None :
481
481
tz = _get_rc_timezone ()
482
482
if not cbook .iterable (x ):
483
- return _from_ordinalf (x , tz , musec_prec )
483
+ return _from_ordinalf (x , tz )
484
484
else :
485
485
x = np .asarray (x )
486
486
if not x .size :
487
487
return x
488
- return _from_ordinalf_np_vectorized (x , tz , musec_prec ).tolist ()
488
+ return _from_ordinalf_np_vectorized (x , tz ).tolist ()
489
489
490
490
491
491
def _ordinalf_to_timedelta (x ):
@@ -561,25 +561,23 @@ class DateFormatter(ticker.Formatter):
561
561
562
562
illegal_s = re .compile (r"((^|[^%])(%%)*%s)" )
563
563
564
- def __init__ (self , fmt , tz = None , musec_prec = 20 ):
564
+ def __init__ (self , fmt , tz = None ):
565
565
"""
566
566
*fmt* is a :func:`strftime` format string; *tz* is the
567
- :class:`tzinfo` instance, *musec_prec* is the microsecond
568
- rounding precision.
567
+ :class:`tzinfo` instance.
569
568
"""
570
569
if tz is None :
571
570
tz = _get_rc_timezone ()
572
571
self .fmt = fmt
573
572
self .tz = tz
574
- self .musec_prec = musec_prec
575
573
576
574
def __call__ (self , x , pos = 0 ):
577
575
if x == 0 :
578
576
raise ValueError ('DateFormatter found a value of x=0, which is '
579
577
'an illegal date. This usually occurs because '
580
578
'you have not informed the axis that it is '
581
579
'plotting dates, e.g., with ax.xaxis_date()' )
582
- dt = num2date (x , self .tz , self . musec_prec )
580
+ dt = num2date (x , self .tz )
583
581
return self .strftime (dt , self .fmt )
584
582
585
583
def set_tzinfo (self , tz ):
@@ -806,8 +804,7 @@ def __call__(self, x, pos=None):
806
804
self .defaultfmt )
807
805
808
806
if isinstance (fmt , six .string_types ):
809
- musec_prec = 1 if fmt .endswith ('%f' ) else 20
810
- self ._formatter = DateFormatter (fmt , self ._tz , musec_prec )
807
+ self ._formatter = DateFormatter (fmt , self ._tz )
811
808
result = self ._formatter (x , pos )
812
809
elif callable (fmt ):
813
810
result = fmt (x , pos )
@@ -953,10 +950,7 @@ def datalim_to_dt(self):
953
950
if dmin > dmax :
954
951
dmin , dmax = dmax , dmin
955
952
956
- mup = 20
957
- if abs (dmax - dmin ) < 1000. / MUSECONDS_PER_DAY :
958
- mup = 1
959
- return num2date (dmin , self .tz , mup ), num2date (dmax , self .tz , mup )
953
+ return num2date (dmin , self .tz ), num2date (dmax , self .tz )
960
954
961
955
def viewlim_to_dt (self ):
962
956
"""
@@ -966,11 +960,7 @@ def viewlim_to_dt(self):
966
960
if vmin > vmax :
967
961
vmin , vmax = vmax , vmin
968
962
969
- mup = 20
970
- if abs (vmax - vmin ) < 1000. / MUSECONDS_PER_DAY :
971
- mup = 1
972
-
973
- return num2date (vmin , self .tz , mup ), num2date (vmax , self .tz , mup )
963
+ return num2date (vmin , self .tz ), num2date (vmax , self .tz )
974
964
975
965
def _get_unit (self ):
976
966
"""
0 commit comments