def generate_range(start=None, end=None, periods=None, offset=BDay()):
from pandas.tseries.frequencies import to_offset<EOL>offset = to_offset(offset)<EOL>start = to_datetime(start)<EOL>end = to_datetime(end)<EOL>if start and not offset.onOffset(start):<EOL><INDENT>start = offset.rollforward(start)<EOL><DEDENT>elif end and not offset.onOffset(end):<EOL><INDENT>end = offset.rollback(end)<EOL><DEDENT>if periods is None and end < start and offset.n >= <NUM_LIT:0>:<EOL><INDENT>end = None<EOL>periods = <NUM_LIT:0><EOL><DEDENT>if end is None:<EOL><INDENT>end = start + (periods - <NUM_LIT:1>) * offset<EOL><DEDENT>if start is None:<EOL><INDENT>start = end - (periods - <NUM_LIT:1>) * offset<EOL><DEDENT>cur = start<EOL>if offset.n >= <NUM_LIT:0>:<EOL><INDENT>while cur <= end:<EOL><INDENT>yield cur<EOL>next_date = offset.apply(cur)<EOL>if next_date <= cur:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>.format(offset=offset))<EOL><DEDENT>cur = next_date<EOL><DEDENT><DEDENT>else:<EOL><INDENT>while cur >= end:<EOL><INDENT>yield cur<EOL>next_date = offset.apply(cur)<EOL>if next_date >= cur:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>.format(offset=offset))<EOL><DEDENT>cur = next_date<EOL><DEDENT><DEDENT>
Generates a sequence of dates corresponding to the specified time
offset. Similar to dateutil.rrule except uses pandas DateOffset
objects to represent time increments.

Parameters
----------
start : datetime (default None)
end : datetime (default None)
periods : int, (default None)
offset : DateOffset, (default BDay())

Notes
-----
* This method is faster for generating weekdays than dateutil.rrule
* At least two of (start, end, periods) must be specified.
* If both start and end are specified, the returned dates will
satisfy start <= date <= end.

Returns
-------
dates : generator object