Skip to content

Commit

Permalink
BUG: raise exception in DateRange with MonthEnd(0) instead of infinit…
Browse files Browse the repository at this point in the history
…e loop, GH #683
  • Loading branch information
wesm committed Jan 26, 2012
1 parent d67f140 commit daf0c67
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pandas/core/daterange.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,11 +502,15 @@ def generate_range(start=None, end=None, periods=None,
if offset._normalizeFirst:
cur = datetools.normalize_date(cur)

next_date = cur
while cur <= end:
yield cur

# faster than cur + offset
cur = offset.apply(cur)
next_date = offset.apply(cur)
if next_date <= cur:
raise ValueError('Offset %s did not increment date' % offset)
cur = next_date

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

Expand Down
4 changes: 4 additions & 0 deletions pandas/tests/test_daterange.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,10 @@ def test_daterange_bug_456(self):
result = rng1.union(rng2)
self.assert_(type(result) == DateRange)

def test_error_with_zero_monthends(self):
self.assertRaises(ValueError, DateRange, '1/1/2000', '1/1/2001',
offset=datetools.MonthEnd(0))

def _skip_if_no_pytz():
try:
import pytz
Expand Down

0 comments on commit daf0c67

Please sign in to comment.