Skip to content

Commit daf0c67

Browse files
committed
BUG: raise exception in DateRange with MonthEnd(0) instead of infinite loop, GH #683
1 parent d67f140 commit daf0c67

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

pandas/core/daterange.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -502,11 +502,15 @@ def generate_range(start=None, end=None, periods=None,
502502
if offset._normalizeFirst:
503503
cur = datetools.normalize_date(cur)
504504

505+
next_date = cur
505506
while cur <= end:
506507
yield cur
507508

508509
# faster than cur + offset
509-
cur = offset.apply(cur)
510+
next_date = offset.apply(cur)
511+
if next_date <= cur:
512+
raise ValueError('Offset %s did not increment date' % offset)
513+
cur = next_date
510514

511515
# Do I want to cache UTC dates? Can't decide...
512516

pandas/tests/test_daterange.py

+4
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,10 @@ def test_daterange_bug_456(self):
350350
result = rng1.union(rng2)
351351
self.assert_(type(result) == DateRange)
352352

353+
def test_error_with_zero_monthends(self):
354+
self.assertRaises(ValueError, DateRange, '1/1/2000', '1/1/2001',
355+
offset=datetools.MonthEnd(0))
356+
353357
def _skip_if_no_pytz():
354358
try:
355359
import pytz

0 commit comments

Comments
 (0)