diff --git a/lib/matplotlib/dates.py b/lib/matplotlib/dates.py index 60bd12ec717..265538e7a74 100755 --- a/lib/matplotlib/dates.py +++ b/lib/matplotlib/dates.py @@ -821,19 +821,6 @@ def tick_values(self, vmin, vmax): self.rule.set(dtstart=start, until=stop) - # estimate the number of ticks very approximately so we don't - # have to do a very expensive (and potentially near infinite) - # 'between' calculation, only to find out it will fail. - nmax, nmin = date2num((vmax, vmin)) - estimate = (nmax - nmin) / (self._get_unit() * self._get_interval()) - # This estimate is only an estimate, so be really conservative - # about bailing... - if estimate > self.MAXTICKS * 2: - raise RuntimeError( - 'RRuleLocator estimated to generate %d ticks from %s to %s: ' - 'exceeds Locator.MAXTICKS * 2 (%d) ' % (estimate, vmin, vmax, - self.MAXTICKS * 2)) - dates = self.rule.between(vmin, vmax, True) if len(dates) == 0: return date2num([vmin, vmax]) @@ -1254,6 +1241,8 @@ def __init__(self, bymonthday=None, interval=1, tz=None): Default is to tick every day of the month: ``bymonthday=range(1,32)`` """ + if not interval == int(interval) or interval < 1: + raise ValueError("interval must be an integer greater than 0") if bymonthday is None: bymonthday = range(1, 32) elif isinstance(bymonthday, np.ndarray): diff --git a/lib/matplotlib/tests/test_dates.py b/lib/matplotlib/tests/test_dates.py index 3a60c05048b..7e0335566eb 100644 --- a/lib/matplotlib/tests/test_dates.py +++ b/lib/matplotlib/tests/test_dates.py @@ -457,6 +457,14 @@ def tz_convert(*args): _test_date2num_dst(pd.date_range, tz_convert) +def test_DayLocator(): + assert_raises(ValueError, mdates.DayLocator, interval=-1) + assert_raises(ValueError, mdates.DayLocator, interval=-1.5) + assert_raises(ValueError, mdates.DayLocator, interval=0) + assert_raises(ValueError, mdates.DayLocator, interval=1.3) + mdates.DayLocator(interval=1.0) + + if __name__ == '__main__': import nose nose.runmodule(argv=['-s', '--with-doctest'], exit=False)