# Buggy code
def _get_index_loc(self, key, base_index=None):
    """
    Get the location of a specific key in an index

    Parameters
    ----------
    key : label
        The key for which to find the location
    base_index : pd.Index, optional
        Optionally the base index to search. If None, the model's index is
        searched.

    Returns
    -------
    loc : int
        The location of the key
    index : pd.Index
        The index including the key; this is a copy of the original index
        unless the index had to be expanded to accomodate `key`.
    index_was_expanded : bool
        Whether or not the index was expanded to accomodate `key`.

    Notes
    -----
    If `key` is past the end of of the given index, and the index is either
    an Int64Index or a date index, this function extends the index up to
    and including key, and then returns the location in the new index.

    """
    if base_index is None:
        base_index = self._index

    index = base_index
    date_index = isinstance(base_index, (PeriodIndex, DatetimeIndex))
    index_class = type(base_index)
    nobs = len(index)

    # Special handling for Int64Index
    if (
        isinstance(index, Int64Index)
        and not date_index
        and isinstance(key, (int, long, np.integer))
    ):
        # Negative indices (that lie in the Index)
        if key < 0 and -key <= nobs:
            key = nobs + key
        # Out-of-sample (note that we include key itself in the new index)
        elif key > base_index[-1]:
            index = Int64Index(np.arange(base_index[0], key + 1))

    # Special handling for date indexes
    if date_index:
        # Integer key (i.e. already given a location)
        if isinstance(key, (int, long, np.integer)):
            # Negative indices (that lie in the Index)
            if key < 0 and -key < nobs:
                key = index[nobs + key]
            # Out-of-sample (note that we include key itself in the new
            # index)
            elif key > len(base_index) - 1:
                index = index_class(
                    start=base_index[0], periods=key + 1, freq=base_index.freq
                )
                key = index[-1]
            else:
                key = index[key]
        # Other key types (i.e. string date or some datetime-like object)
        else:
            # Covert the key to the appropriate date-like object
            if index_class is PeriodIndex:
                date_key = Period(key, freq=base_index.freq)
            else:
                date_key = Timestamp(key)

            # Out-of-sample
            if date_key > base_index[-1]:
                # First create an index that may not always include `key`
                index = index_class(
                    start=base_index[0], end=date_key, freq=base_index.freq
                )

                # Now make sure we include `key`
                if not index[-1] == date_key:
                    index = index_class(
                        start=base_index[0],
                        periods=len(index) + 1,
                        freq=base_index.freq,
                    )

    # Get the location (note that get_loc will throw a KeyError if key is
    # invalid)
    loc = index.get_loc(key)

    # Check if we now have a modified index
    index_was_expanded = index is not base_index

    # (Never return the actual index object)
    if not index_was_expanded:
        index = index.copy()

    # Return the index through the end of the loc / slice
    if isinstance(loc, slice):
        end = loc.stop
    else:
        end = loc

    return loc, index[: end + 1], index_was_expanded


# Traceback (ValueError)
======================================================================
ERROR: statsmodels.tsa.statespace.tests.test_sarimax.test_misc_exog
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Py\lib\site-packages\nose\case.py", line 197, in runTest
self.test(*self.arg)
File "C:\projects\statsmodels\statsmodels\tsa\statespace\tests\test_sarimax.py", line 1982, in test_misc_exog
res.forecast(steps=1, exog=oos_exog)
File "C:\projects\statsmodels\statsmodels\base\wrapper.py", line 95, in wrapper
obj = data.wrap_output(func(results, *args, **kwargs), how)
File "C:\projects\statsmodels\statsmodels\tsa\statespace\mlemodel.py", line 2401, in forecast
return self.predict(start=self.nobs, end=end, **kwargs)
File "C:\projects\statsmodels\statsmodels\tsa\statespace\mlemodel.py", line 2374, in predict
prediction_results = self.get_prediction(start, end, dynamic, **kwargs)
File "C:\projects\statsmodels\statsmodels\tsa\statespace\sarimax.py", line 1889, in get_prediction
self.model._get_prediction_index(start, end, index, silent=True))
File "C:\projects\statsmodels\statsmodels\tsa\base\tsa_model.py", line 447, in _get_prediction_index
start, start_index, start_oos = self._get_index_label_loc(start)
File "C:\projects\statsmodels\statsmodels\tsa\base\tsa_model.py", line 383, in _get_index_label_loc
self._get_index_loc(key, base_index))
File "C:\projects\statsmodels\statsmodels\tsa\base\tsa_model.py", line 308, in _get_index_loc
freq=base_index.freq)
File "C:\Py\lib\site-packages\pandas\util\decorators.py", line 91, in wrapper
return func(*args, **kwargs)
File "C:\Py\lib\site-packages\pandas\tseries\index.py", line 301, in __new__
ambiguous=ambiguous)
File "C:\Py\lib\site-packages\pandas\tseries\index.py", line 506, in _generate
index = _generate_regular_range(start, end, periods, offset)
File "C:\Py\lib\site-packages\pandas\tseries\index.py", line 1977, in _generate_regular_range
dates = list(xdr)
File "C:\Py\lib\site-packages\pandas\tseries\offsets.py", line 2894, in generate_range
end = start + (periods - 1) * offset
File "C:\Py\lib\site-packages\pandas\tseries\offsets.py", line 395, in __radd__
return self.__add__(other)
File "C:\Py\lib\site-packages\pandas\tseries\offsets.py", line 390, in __add__
return self.apply(other)
File "C:\Py\lib\site-packages\pandas\tseries\offsets.py", line 70, in wrapper
result = func(self, other)
File "C:\Py\lib\site-packages\pandas\tseries\offsets.py", line 2041, in apply
other = other + relativedelta(months=3 * n - monthsSince, day=1)
File "C:\Py\lib\site-packages\dateutil\relativedelta.py", line 383, in __radd__
return self.__add__(other)
File "C:\Py\lib\site-packages\dateutil\relativedelta.py", line 365, in __add__
ret = (other.replace(**repl)
File "pandas\tslib.pyx", line 697, in pandas.tslib.Timestamp.replace (pandas\tslib.c:14489)
File "pandas\tslib.pyx", line 691, in pandas.tslib.Timestamp.replace.validate (pandas\tslib.c:14143)
ValueError: value must be an integer, received <type 'long'> for year
======================================================================
ERROR: statsmodels.tsa.statespace.tests.test_structural.test_misc_exog
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Py\lib\site-packages\nose\case.py", line 197, in runTest
self.test(*self.arg)
File "C:\projects\statsmodels\statsmodels\tsa\statespace\tests\test_structural.py", line 334, in test_misc_exog
res.forecast(steps=1, exog=oos_exog)
File "C:\projects\statsmodels\statsmodels\base\wrapper.py", line 95, in wrapper
obj = data.wrap_output(func(results, *args, **kwargs), how)
File "C:\projects\statsmodels\statsmodels\tsa\statespace\mlemodel.py", line 2401, in forecast
return self.predict(start=self.nobs, end=end, **kwargs)
File "C:\projects\statsmodels\statsmodels\tsa\statespace\mlemodel.py", line 2374, in predict
prediction_results = self.get_prediction(start, end, dynamic, **kwargs)
File "C:\projects\statsmodels\statsmodels\tsa\statespace\structural.py", line 1486, in get_prediction
self.model._get_prediction_index(start, end, index, silent=True))
File "C:\projects\statsmodels\statsmodels\tsa\base\tsa_model.py", line 447, in _get_prediction_index
start, start_index, start_oos = self._get_index_label_loc(start)
File "C:\projects\statsmodels\statsmodels\tsa\base\tsa_model.py", line 383, in _get_index_label_loc
self._get_index_loc(key, base_index))
File "C:\projects\statsmodels\statsmodels\tsa\base\tsa_model.py", line 308, in _get_index_loc
freq=base_index.freq)
File "C:\Py\lib\site-packages\pandas\util\decorators.py", line 91, in wrapper
return func(*args, **kwargs)
File "C:\Py\lib\site-packages\pandas\tseries\index.py", line 301, in __new__
ambiguous=ambiguous)
File "C:\Py\lib\site-packages\pandas\tseries\index.py", line 506, in _generate
index = _generate_regular_range(start, end, periods, offset)
File "C:\Py\lib\site-packages\pandas\tseries\index.py", line 1977, in _generate_regular_range
dates = list(xdr)
File "C:\Py\lib\site-packages\pandas\tseries\offsets.py", line 2894, in generate_range
end = start + (periods - 1) * offset
File "C:\Py\lib\site-packages\pandas\tseries\offsets.py", line 395, in __radd__
return self.__add__(other)
File "C:\Py\lib\site-packages\pandas\tseries\offsets.py", line 390, in __add__
return self.apply(other)
File "C:\Py\lib\site-packages\pandas\tseries\offsets.py", line 70, in wrapper
result = func(self, other)
File "C:\Py\lib\site-packages\pandas\tseries\offsets.py", line 2041, in apply
other = other + relativedelta(months=3 * n - monthsSince, day=1)
File "C:\Py\lib\site-packages\dateutil\relativedelta.py", line 383, in __radd__
return self.__add__(other)
File "C:\Py\lib\site-packages\dateutil\relativedelta.py", line 365, in __add__
ret = (other.replace(**repl)
File "pandas\tslib.pyx", line 697, in pandas.tslib.Timestamp.replace (pandas\tslib.c:14489)
File "pandas\tslib.pyx", line 691, in pandas.tslib.Timestamp.replace.validate (pandas\tslib.c:14143)
ValueError: value must be an integer, received <type 'long'> for year
======================================================================
ERROR: statsmodels.tsa.statespace.tests.test_varmax.TestVAR_exog.test_forecast
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Py\lib\site-packages\nose\case.py", line 197, in runTest
self.test(*self.arg)
File "C:\projects\statsmodels\statsmodels\tsa\statespace\tests\test_varmax.py", line 437, in test_forecast
desired = self.results.forecast(steps=16, exog=exog)
File "C:\projects\statsmodels\statsmodels\base\wrapper.py", line 95, in wrapper
obj = data.wrap_output(func(results, *args, **kwargs), how)
File "C:\projects\statsmodels\statsmodels\tsa\statespace\mlemodel.py", line 2401, in forecast
return self.predict(start=self.nobs, end=end, **kwargs)
File "C:\projects\statsmodels\statsmodels\tsa\statespace\mlemodel.py", line 2374, in predict
prediction_results = self.get_prediction(start, end, dynamic, **kwargs)
File "C:\projects\statsmodels\statsmodels\tsa\statespace\varmax.py", line 781, in get_prediction
self.model._get_prediction_index(start, end, index, silent=True))
File "C:\projects\statsmodels\statsmodels\tsa\base\tsa_model.py", line 447, in _get_prediction_index
start, start_index, start_oos = self._get_index_label_loc(start)
File "C:\projects\statsmodels\statsmodels\tsa\base\tsa_model.py", line 383, in _get_index_label_loc
self._get_index_loc(key, base_index))
File "C:\projects\statsmodels\statsmodels\tsa\base\tsa_model.py", line 308, in _get_index_loc
freq=base_index.freq)
File "C:\Py\lib\site-packages\pandas\util\decorators.py", line 91, in wrapper
return func(*args, **kwargs)
File "C:\Py\lib\site-packages\pandas\tseries\index.py", line 301, in __new__
ambiguous=ambiguous)
File "C:\Py\lib\site-packages\pandas\tseries\index.py", line 506, in _generate
index = _generate_regular_range(start, end, periods, offset)
File "C:\Py\lib\site-packages\pandas\tseries\index.py", line 1977, in _generate_regular_range
dates = list(xdr)
File "C:\Py\lib\site-packages\pandas\tseries\offsets.py", line 2894, in generate_range
end = start + (periods - 1) * offset
File "C:\Py\lib\site-packages\pandas\tseries\offsets.py", line 395, in __radd__
return self.__add__(other)
File "C:\Py\lib\site-packages\pandas\tseries\offsets.py", line 390, in __add__
return self.apply(other)
File "C:\Py\lib\site-packages\pandas\tseries\offsets.py", line 70, in wrapper
result = func(self, other)
File "C:\Py\lib\site-packages\pandas\tseries\offsets.py", line 2041, in apply
other = other + relativedelta(months=3 * n - monthsSince, day=1)
File "C:\Py\lib\site-packages\dateutil\relativedelta.py", line 383, in __radd__
return self.__add__(other)
File "C:\Py\lib\site-packages\dateutil\relativedelta.py", line 365, in __add__
ret = (other.replace(**repl)
File "pandas\tslib.pyx", line 697, in pandas.tslib.Timestamp.replace (pandas\tslib.c:14489)
File "pandas\tslib.pyx", line 691, in pandas.tslib.Timestamp.replace.validate (pandas\tslib.c:14143)
ValueError: value must be an integer, received <type 'long'> for year
======================================================================
ERROR: statsmodels.tsa.statespace.tests.test_varmax.TestVAR_exog2.test_forecast
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Py\lib\site-packages\nose\case.py", line 197, in runTest
self.test(*self.arg)
File "C:\projects\statsmodels\statsmodels\tsa\statespace\tests\test_varmax.py", line 528, in test_forecast
desired = self.results.forecast(steps=16, exog=exog)
File "C:\projects\statsmodels\statsmodels\base\wrapper.py", line 95, in wrapper
obj = data.wrap_output(func(results, *args, **kwargs), how)
File "C:\projects\statsmodels\statsmodels\tsa\statespace\mlemodel.py", line 2401, in forecast
return self.predict(start=self.nobs, end=end, **kwargs)
File "C:\projects\statsmodels\statsmodels\tsa\statespace\mlemodel.py", line 2374, in predict
prediction_results = self.get_prediction(start, end, dynamic, **kwargs)
File "C:\projects\statsmodels\statsmodels\tsa\statespace\varmax.py", line 781, in get_prediction
self.model._get_prediction_index(start, end, index, silent=True))
File "C:\projects\statsmodels\statsmodels\tsa\base\tsa_model.py", line 447, in _get_prediction_index
start, start_index, start_oos = self._get_index_label_loc(start)
File "C:\projects\statsmodels\statsmodels\tsa\base\tsa_model.py", line 383, in _get_index_label_loc
self._get_index_loc(key, base_index))
File "C:\projects\statsmodels\statsmodels\tsa\base\tsa_model.py", line 308, in _get_index_loc
freq=base_index.freq)
File "C:\Py\lib\site-packages\pandas\util\decorators.py", line 91, in wrapper
return func(*args, **kwargs)
File "C:\Py\lib\site-packages\pandas\tseries\index.py", line 301, in __new__
ambiguous=ambiguous)
File "C:\Py\lib\site-packages\pandas\tseries\index.py", line 506, in _generate
index = _generate_regular_range(start, end, periods, offset)
File "C:\Py\lib\site-packages\pandas\tseries\index.py", line 1977, in _generate_regular_range
dates = list(xdr)
File "C:\Py\lib\site-packages\pandas\tseries\offsets.py", line 2894, in generate_range
end = start + (periods - 1) * offset
File "C:\Py\lib\site-packages\pandas\tseries\offsets.py", line 395, in __radd__
return self.__add__(other)
File "C:\Py\lib\site-packages\pandas\tseries\offsets.py", line 390, in __add__
return self.apply(other)
File "C:\Py\lib\site-packages\pandas\tseries\offsets.py", line 70, in wrapper
result = func(self, other)
File "C:\Py\lib\site-packages\pandas\tseries\offsets.py", line 2041, in apply
other = other + relativedelta(months=3 * n - monthsSince, day=1)
File "C:\Py\lib\site-packages\dateutil\relativedelta.py", line 383, in __radd__
return self.__add__(other)
File "C:\Py\lib\site-packages\dateutil\relativedelta.py", line 365, in __add__
ret = (other.replace(**repl)
File "pandas\tslib.pyx", line 697, in pandas.tslib.Timestamp.replace (pandas\tslib.c:14489)
File "pandas\tslib.pyx", line 691, in pandas.tslib.Timestamp.replace.validate (pandas\tslib.c:14143)
ValueError: value must be an integer, received <type 'long'> for year
======================================================================
ERROR: statsmodels.tsa.statespace.tests.test_varmax.test_misc_exog
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Py\lib\site-packages\nose\case.py", line 197, in runTest
self.test(*self.arg)
File "C:\projects\statsmodels\statsmodels\tsa\statespace\tests\test_varmax.py", line 817, in test_misc_exog
res.forecast(steps=1, exog=oos_exog)
File "C:\projects\statsmodels\statsmodels\base\wrapper.py", line 95, in wrapper
obj = data.wrap_output(func(results, *args, **kwargs), how)
File "C:\projects\statsmodels\statsmodels\tsa\statespace\mlemodel.py", line 2401, in forecast
return self.predict(start=self.nobs, end=end, **kwargs)
File "C:\projects\statsmodels\statsmodels\tsa\statespace\mlemodel.py", line 2374, in predict
prediction_results = self.get_prediction(start, end, dynamic, **kwargs)
File "C:\projects\statsmodels\statsmodels\tsa\statespace\varmax.py", line 781, in get_prediction
self.model._get_prediction_index(start, end, index, silent=True))
File "C:\projects\statsmodels\statsmodels\tsa\base\tsa_model.py", line 447, in _get_prediction_index
start, start_index, start_oos = self._get_index_label_loc(start)
File "C:\projects\statsmodels\statsmodels\tsa\base\tsa_model.py", line 383, in _get_index_label_loc
self._get_index_loc(key, base_index))
File "C:\projects\statsmodels\statsmodels\tsa\base\tsa_model.py", line 308, in _get_index_loc
freq=base_index.freq)
File "C:\Py\lib\site-packages\pandas\util\decorators.py", line 91, in wrapper
return func(*args, **kwargs)
File "C:\Py\lib\site-packages\pandas\tseries\index.py", line 301, in __new__
ambiguous=ambiguous)
File "C:\Py\lib\site-packages\pandas\tseries\index.py", line 506, in _generate
index = _generate_regular_range(start, end, periods, offset)
File "C:\Py\lib\site-packages\pandas\tseries\index.py", line 1977, in _generate_regular_range
dates = list(xdr)
File "C:\Py\lib\site-packages\pandas\tseries\offsets.py", line 2894, in generate_range
end = start + (periods - 1) * offset
File "C:\Py\lib\site-packages\pandas\tseries\offsets.py", line 395, in __radd__
return self.__add__(other)
File "C:\Py\lib\site-packages\pandas\tseries\offsets.py", line 390, in __add__
return self.apply(other)
File "C:\Py\lib\site-packages\pandas\tseries\offsets.py", line 70, in wrapper
result = func(self, other)
File "C:\Py\lib\site-packages\pandas\tseries\offsets.py", line 2041, in apply
other = other + relativedelta(months=3 * n - monthsSince, day=1)
File "C:\Py\lib\site-packages\dateutil\relativedelta.py", line 383, in __radd__
return self.__add__(other)
File "C:\Py\lib\site-packages\dateutil\relativedelta.py", line 365, in __add__
ret = (other.replace(**repl)
File "pandas\tslib.pyx", line 697, in pandas.tslib.Timestamp.replace (pandas\tslib.c:14489)
File "pandas\tslib.pyx", line 691, in pandas.tslib.Timestamp.replace.validate (pandas\tslib.c:14143)
ValueError: value must be an integer, received <type 'long'> for year

# Fixed code
def _get_index_loc(self, key, base_index=None):
    """
    Get the location of a specific key in an index

    Parameters
    ----------
    key : label
        The key for which to find the location
    base_index : pd.Index, optional
        Optionally the base index to search. If None, the model's index is
        searched.

    Returns
    -------
    loc : int
        The location of the key
    index : pd.Index
        The index including the key; this is a copy of the original index
        unless the index had to be expanded to accomodate `key`.
    index_was_expanded : bool
        Whether or not the index was expanded to accomodate `key`.

    Notes
    -----
    If `key` is past the end of of the given index, and the index is either
    an Int64Index or a date index, this function extends the index up to
    and including key, and then returns the location in the new index.

    """
    if base_index is None:
        base_index = self._index

    index = base_index
    date_index = isinstance(base_index, (PeriodIndex, DatetimeIndex))
    index_class = type(base_index)
    nobs = len(index)

    # Special handling for Int64Index
    if (
        isinstance(index, Int64Index)
        and not date_index
        and isinstance(key, (int, long, np.integer))
    ):
        # Negative indices (that lie in the Index)
        if key < 0 and -key <= nobs:
            key = nobs + key
        # Out-of-sample (note that we include key itself in the new index)
        elif key > base_index[-1]:
            index = Int64Index(np.arange(base_index[0], int(key + 1)))

    # Special handling for date indexes
    if date_index:
        # Integer key (i.e. already given a location)
        if isinstance(key, (int, long, np.integer)):
            # Negative indices (that lie in the Index)
            if key < 0 and -key < nobs:
                key = index[nobs + key]
            # Out-of-sample (note that we include key itself in the new
            # index)
            elif key > len(base_index) - 1:
                index = index_class(
                    start=base_index[0], periods=int(key + 1), freq=base_index.freq
                )
                key = index[-1]
            else:
                key = index[key]
        # Other key types (i.e. string date or some datetime-like object)
        else:
            # Covert the key to the appropriate date-like object
            if index_class is PeriodIndex:
                date_key = Period(key, freq=base_index.freq)
            else:
                date_key = Timestamp(key)

            # Out-of-sample
            if date_key > base_index[-1]:
                # First create an index that may not always include `key`
                index = index_class(
                    start=base_index[0], end=date_key, freq=base_index.freq
                )

                # Now make sure we include `key`
                if not index[-1] == date_key:
                    index = index_class(
                        start=base_index[0],
                        periods=len(index) + 1,
                        freq=base_index.freq,
                    )

    # Get the location (note that get_loc will throw a KeyError if key is
    # invalid)
    loc = index.get_loc(key)

    # Check if we now have a modified index
    index_was_expanded = index is not base_index

    # (Never return the actual index object)
    if not index_was_expanded:
        index = index.copy()

    # Return the index through the end of the loc / slice
    if isinstance(loc, slice):
        end = loc.stop
    else:
        end = loc

    return loc, index[: end + 1], index_was_expanded