Skip to content

Commit

Permalink
Merge pull request #6955 from LindyBalboa/issue_6935
Browse files Browse the repository at this point in the history
MNT: Add parameter checks to DayLocator initiator
  • Loading branch information
tacaswell committed Aug 22, 2016
2 parents 947e6eb + 160c55d commit a53c4b3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
15 changes: 2 additions & 13 deletions lib/matplotlib/dates.py
Expand Up @@ -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])
Expand Down Expand Up @@ -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):
Expand Down
8 changes: 8 additions & 0 deletions lib/matplotlib/tests/test_dates.py
Expand Up @@ -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)

0 comments on commit a53c4b3

Please sign in to comment.