Repository: statsmodels/statsmodels

Issue:
BUG: pandas 0.19.2 compatibility - long versus integer in timestamp 
This looks like a new failure with pandas 0.19.2 on appveyor windows python 2.7, it passes on python 3.5.
The unit tests passed with pandas 0.19.1 in previous run at https://ci.appveyor.com/project/josef-pkt/statsmodels/build/1.0.1076/job/863r6ag0kup7wspa

failing in a PR that is the latest test run:
https://ci.appveyor.com/project/josef-pkt/statsmodels/build/1.0.1094/job/7qac29xs07orl9pw

```

======================================================================
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

```


Discussion:
@ChadFulton  @jreback 

Any idea about this?

here is a replicated failure in [pandas](https://ci.appveyor.com/project/jreback/pandas/build/job/4evdeu8bxd4ot4du) with this commit
https://github.com/jreback/pandas/commit/dcef5f2afe8671bde467333c71551b0164374bfc

I have a fix prepared for pandas, but easiest for you to change is to pass ``int(keys + 1)`` rather than ``keys + 1``. annoying I know, but only checking for ints here (and not compat with 2.7 longs)..... 

File "C:\projects\statsmodels\statsmodels\tsa\base\tsa_model.py", line 308, in _get_index_loc
 (do the change here)
@jreback  Thanks, I will make the change.

Debian is currently adopting pandas 0.19.2. statsmodels is green there.

Just as background information: Is there anything specific about Windows with python 2.7 that it fails only there?
my mistake: I think this is refactored code in master and is not in statsmodels 0.8, so not relevant for current Debian testing and backporting

so on py2.7, on 32-bit platforms, ints are generally longs (and not actual ints). We have a compat routine (e.g. for py2 and py3) that checks these things as ``isinstance(value, int)`` is not sufficient. 



Resolving patch:
diff --git a/statsmodels/tsa/base/tsa_model.py b/statsmodels/tsa/base/tsa_model.py
--- a/statsmodels/tsa/base/tsa_model.py
+++ b/statsmodels/tsa/base/tsa_model.py
@@ -292,7 +292,7 @@ def _get_index_loc(self, key, base_index=None):
                 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))
+                index = Int64Index(np.arange(base_index[0], int(key + 1)))
 
         # Special handling for date indexes
         if date_index:
@@ -304,7 +304,8 @@ def _get_index_loc(self, key, base_index=None):
                 # 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,
+                    index = index_class(start=base_index[0],
+                                        periods=int(key + 1),
                                         freq=base_index.freq)
                     key = index[-1]
                 else:


Test patch: