# Buggy code
def apply_index(self, i):
    """
    Vectorized apply of DateOffset to DatetimeIndex,
    raises NotImplentedError for offsets without a
    vectorized implementation.

    Parameters
    ----------
    i : DatetimeIndex

    Returns
    -------
    y : DatetimeIndex
    """

    if type(self) is not DateOffset:
        raise NotImplementedError(
            "DateOffset subclass {name} "
            "does not have a vectorized "
            "implementation".format(name=self.__class__.__name__)
        )
    kwds = self.kwds
    relativedelta_fast = {
        "years",
        "months",
        "weeks",
        "days",
        "hours",
        "minutes",
        "seconds",
        "microseconds",
    }
    # relativedelta/_offset path only valid for base DateOffset
    if self._use_relativedelta and set(kwds).issubset(relativedelta_fast):
        months = (kwds.get("years", 0) * 12 + kwds.get("months", 0)) * self.n
        if months:
            shifted = liboffsets.shift_months(i.asi8, months)
            i = type(i)(shifted, freq=i.freq, dtype=i.dtype)

        weeks = (kwds.get("weeks", 0)) * self.n
        if weeks:
            # integer addition on PeriodIndex is deprecated,
            #   so we directly use _time_shift instead
            asper = i.to_period("W")
            if not isinstance(asper._data, np.ndarray):
                # unwrap PeriodIndex --> PeriodArray
                asper = asper._data
            shifted = asper._time_shift(weeks)
            i = shifted.to_timestamp() + i.to_perioddelta("W")

        timedelta_kwds = {
            k: v
            for k, v in kwds.items()
            if k in ["days", "hours", "minutes", "seconds", "microseconds"]
        }
        if timedelta_kwds:
            delta = Timedelta(**timedelta_kwds)
            i = i + (self.n * delta)
        return i
    elif not self._use_relativedelta and hasattr(self, "_offset"):
        # timedelta
        return i + (self._offset * self.n)
    else:
        # relativedelta with other keywords
        kwd = set(kwds) - relativedelta_fast
        raise NotImplementedError(
            "DateOffset with relativedelta "
            "keyword(s) {kwd} not able to be "
            "applied vectorized".format(kwd=kwd)
        )


# Traceback (ValueError)
Traceback (most recent call last):
File "C:\mma\local\Anaconda3\envs\pd24\lib\site-packages\pandas\core\arrays\datetimelike.py", line 884, in _validate_frequency
raise ValueError
ValueError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\mma\local\Anaconda3\envs\pd24\lib\site-packages\pandas\core\indexes\datetimelike.py", line 489, in __add__
result = self._data.__add__(maybe_unwrap_index(other))
File "C:\mma\local\Anaconda3\envs\pd24\lib\site-packages\pandas\core\arrays\datetimelike.py", line 1190, in __add__
result = self._add_offset(other)
File "C:\mma\local\Anaconda3\envs\pd24\lib\site-packages\pandas\core\arrays\datetimes.py", line 737, in _add_offset
result = offset.apply_index(values)
File "pandas/_libs/tslibs/offsets.pyx", line 116, in pandas._libs.tslibs.offsets.apply_index_wraps.wrapper
File "C:\mma\local\Anaconda3\envs\pd24\lib\site-packages\pandas\tseries\offsets.py", line 278, in apply_index
i = type(i)(shifted, freq=i.freq, dtype=i.dtype)
File "C:\mma\local\Anaconda3\envs\pd24\lib\site-packages\pandas\core\arrays\datetimes.py", line 351, in __init__
type(self)._validate_frequency(self, freq)
File "C:\mma\local\Anaconda3\envs\pd24\lib\site-packages\pandas\core\arrays\datetimelike.py", line 897, in _validate_frequency
.format(infer=inferred, passed=freq.freqstr))
ValueError: Inferred frequency AS-APR from passed values does not conform to passed frequency AS-JAN

# Fixed code
def apply_index(self, i):
    """
    Vectorized apply of DateOffset to DatetimeIndex,
    raises NotImplentedError for offsets without a
    vectorized implementation.

    Parameters
    ----------
    i : DatetimeIndex

    Returns
    -------
    y : DatetimeIndex
    """

    if type(self) is not DateOffset:
        raise NotImplementedError(
            "DateOffset subclass {name} "
            "does not have a vectorized "
            "implementation".format(name=self.__class__.__name__)
        )
    kwds = self.kwds
    relativedelta_fast = {
        "years",
        "months",
        "weeks",
        "days",
        "hours",
        "minutes",
        "seconds",
        "microseconds",
    }
    # relativedelta/_offset path only valid for base DateOffset
    if self._use_relativedelta and set(kwds).issubset(relativedelta_fast):
        months = (kwds.get("years", 0) * 12 + kwds.get("months", 0)) * self.n
        if months:
            shifted = liboffsets.shift_months(i.asi8, months)
            i = type(i)(shifted, dtype=i.dtype)

        weeks = (kwds.get("weeks", 0)) * self.n
        if weeks:
            # integer addition on PeriodIndex is deprecated,
            #   so we directly use _time_shift instead
            asper = i.to_period("W")
            if not isinstance(asper._data, np.ndarray):
                # unwrap PeriodIndex --> PeriodArray
                asper = asper._data
            shifted = asper._time_shift(weeks)
            i = shifted.to_timestamp() + i.to_perioddelta("W")

        timedelta_kwds = {
            k: v
            for k, v in kwds.items()
            if k in ["days", "hours", "minutes", "seconds", "microseconds"]
        }
        if timedelta_kwds:
            delta = Timedelta(**timedelta_kwds)
            i = i + (self.n * delta)
        return i
    elif not self._use_relativedelta and hasattr(self, "_offset"):
        # timedelta
        return i + (self._offset * self.n)
    else:
        # relativedelta with other keywords
        kwd = set(kwds) - relativedelta_fast
        raise NotImplementedError(
            "DateOffset with relativedelta "
            "keyword(s) {kwd} not able to be "
            "applied vectorized".format(kwd=kwd)
        )