# Buggy code
def generate_range(start=None, end=None, periods=None, offset=BDay(), time_rule=None):
    """
    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, optional

    Note
    ----
    * 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

    """
    if time_rule is not None:
        from pandas.tseries.frequencies import get_offset

        offset = get_offset(time_rule)

    start = to_datetime(start)
    end = to_datetime(end)

    if start and not offset.onOffset(start):
        start = offset.rollforward(start)

    if end and not offset.onOffset(end):
        end = offset.rollback(end)

        if periods is None and end < start:
            end = None
            periods = 0

    if end is None:
        end = start + (periods - 1) * offset

    if start is None:
        start = end - (periods - 1) * offset

    cur = start

    next_date = cur
    while cur <= end:
        yield cur

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


# Traceback (AttributeError)
======================================================================
ERROR: test_shift_multiple_of_same_base (__main__.TestLegacySupport)
----------------------------------------------------------------------
Traceback (most recent call last):
File "pandas/tests/test_timeseries.py", line 624, in test_shift_multiple_of_same_base
ts = Series(np.random.randn(5), index=date_range('1/1/2000', freq='H'))
File "/home/wesm/code/pandas/pandas/core/daterange.py", line 65, in date_range
freq=freq, tz=tz, normalize=normalize)
File "/home/wesm/code/pandas/pandas/core/index.py", line 1279, in __new__
b, e = Timestamp(start), Timestamp(end)
File "datetime.pyx", line 59, in pandas._tseries.Timestamp.__new__ (pandas/src/tseries.c:27720)
AttributeError: 'NoneType' object has no attribute 'dtval'

----------------------------------------------------------------------

# Fixed code
def generate_range(start=None, end=None, periods=None, offset=BDay(), time_rule=None):
    """
    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, optional

    Note
    ----
    * 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

    """
    if time_rule is not None:
        from pandas.tseries.frequencies import get_offset

        offset = get_offset(time_rule)

    start = to_datetime(start)
    end = to_datetime(end)

    if start and not offset.onOffset(start):
        start = offset.rollforward(start)

    if end and not offset.onOffset(end):
        end = offset.rollback(end)

        if periods is None and end < start:
            end = None
            periods = 0

    if _count_not_none(start, end, periods) < 2:
        raise ValueError("Must specify 2 of start, end, periods")

    if end is None:
        end = start + (periods - 1) * offset

    if start is None:
        start = end - (periods - 1) * offset

    cur = start

    next_date = cur
    while cur <= end:
        yield cur

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