Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1451d5c

Browse files
author
James Evans
committed
Fixed a bug in RRuleLocator that generated invalid datetimes when padding the axes bounds for large ranges of times or with times that are close to the boundaries of valid datetimes.
svn path=/trunk/matplotlib/; revision=6872
1 parent d49fc95 commit 1451d5c

1 file changed

Lines changed: 28 additions & 2 deletions

File tree

lib/matplotlib/dates.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,20 @@ def __call__(self):
481481
if dmin>dmax:
482482
dmax, dmin = dmin, dmax
483483
delta = relativedelta(dmax, dmin)
484-
self.rule.set(dtstart=dmin-delta, until=dmax+delta)
484+
485+
# We need to cap at the endpoints of valid datetime
486+
try:
487+
start = dmin - delta
488+
except ValueError:
489+
start = _from_ordinalf( 1.0 )
490+
491+
try:
492+
stop = dmax + delta
493+
except ValueError:
494+
# The magic number!
495+
stop = _from_ordinalf( 3652059.9999999 )
496+
497+
self.rule.set(dtstart=start, until=stop)
485498
dates = self.rule.between(dmin, dmax, True)
486499
return date2num(dates)
487500

@@ -518,7 +531,20 @@ def autoscale(self):
518531
dmax, dmin = dmin, dmax
519532

520533
delta = relativedelta(dmax, dmin)
521-
self.rule.set(dtstart=dmin-delta, until=dmax+delta)
534+
535+
# We need to cap at the endpoints of valid datetime
536+
try:
537+
start = dmin - delta
538+
except ValueError:
539+
start = _from_ordinalf( 1.0 )
540+
541+
try:
542+
stop = dmax + delta
543+
except ValueError:
544+
# The magic number!
545+
stop = _from_ordinalf( 3652059.9999999 )
546+
547+
self.rule.set(dtstart=start, until=stop)
522548
dmin, dmax = self.datalim_to_dt()
523549

524550

0 commit comments

Comments
 (0)