Skip to content

Commit a53c4b3

Browse files
authored
Merge pull request #6955 from LindyBalboa/issue_6935
MNT: Add parameter checks to DayLocator initiator
2 parents 947e6eb + 160c55d commit a53c4b3

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

lib/matplotlib/dates.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -821,19 +821,6 @@ def tick_values(self, vmin, vmax):
821821

822822
self.rule.set(dtstart=start, until=stop)
823823

824-
# estimate the number of ticks very approximately so we don't
825-
# have to do a very expensive (and potentially near infinite)
826-
# 'between' calculation, only to find out it will fail.
827-
nmax, nmin = date2num((vmax, vmin))
828-
estimate = (nmax - nmin) / (self._get_unit() * self._get_interval())
829-
# This estimate is only an estimate, so be really conservative
830-
# about bailing...
831-
if estimate > self.MAXTICKS * 2:
832-
raise RuntimeError(
833-
'RRuleLocator estimated to generate %d ticks from %s to %s: '
834-
'exceeds Locator.MAXTICKS * 2 (%d) ' % (estimate, vmin, vmax,
835-
self.MAXTICKS * 2))
836-
837824
dates = self.rule.between(vmin, vmax, True)
838825
if len(dates) == 0:
839826
return date2num([vmin, vmax])
@@ -1254,6 +1241,8 @@ def __init__(self, bymonthday=None, interval=1, tz=None):
12541241
12551242
Default is to tick every day of the month: ``bymonthday=range(1,32)``
12561243
"""
1244+
if not interval == int(interval) or interval < 1:
1245+
raise ValueError("interval must be an integer greater than 0")
12571246
if bymonthday is None:
12581247
bymonthday = range(1, 32)
12591248
elif isinstance(bymonthday, np.ndarray):

lib/matplotlib/tests/test_dates.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,14 @@ def tz_convert(*args):
457457
_test_date2num_dst(pd.date_range, tz_convert)
458458

459459

460+
def test_DayLocator():
461+
assert_raises(ValueError, mdates.DayLocator, interval=-1)
462+
assert_raises(ValueError, mdates.DayLocator, interval=-1.5)
463+
assert_raises(ValueError, mdates.DayLocator, interval=0)
464+
assert_raises(ValueError, mdates.DayLocator, interval=1.3)
465+
mdates.DayLocator(interval=1.0)
466+
467+
460468
if __name__ == '__main__':
461469
import nose
462470
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

0 commit comments

Comments
 (0)