From 380ace170de3672bd0f7e26678ec227ae406a772 Mon Sep 17 00:00:00 2001 From: Jeff Reback Date: Sun, 1 Jan 2017 12:10:58 -0500 Subject: [PATCH] COMPAT: py2.7 compat for Timestamp.replace xref https://github.com/statsmodels/statsmodels/issues/3349 --- doc/source/whatsnew/v0.20.0.txt | 2 +- pandas/tseries/tests/test_timeseries.py | 11 +++++++++++ pandas/tslib.pyx | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v0.20.0.txt b/doc/source/whatsnew/v0.20.0.txt index a947b4f3ca0ac..bbf528a50e1bb 100644 --- a/doc/source/whatsnew/v0.20.0.txt +++ b/doc/source/whatsnew/v0.20.0.txt @@ -305,7 +305,7 @@ Bug Fixes - Bug in ``Series`` construction with a datetimetz (:issue:`14928`) - +- Bug in compat for passing long integers to ``Timestamp.replace`` (:issue:`15030`) diff --git a/pandas/tseries/tests/test_timeseries.py b/pandas/tseries/tests/test_timeseries.py index 3f4a10619f7f5..1834c56e59bb9 100644 --- a/pandas/tseries/tests/test_timeseries.py +++ b/pandas/tseries/tests/test_timeseries.py @@ -1883,6 +1883,17 @@ def test_timestamp_date_out_of_range(self): self.assertRaises(ValueError, DatetimeIndex, ['1400-01-01']) self.assertRaises(ValueError, DatetimeIndex, [datetime(1400, 1, 1)]) + def test_compat_replace(self): + # https://github.com/statsmodels/statsmodels/issues/3349 + # replace should take ints/longs for compat + + for f in [compat.long, int]: + result = date_range(Timestamp('1960-04-01 00:00:00', + freq='QS-JAN'), + periods=f(76), + freq='QS-JAN') + self.assertEqual(len(result), 76) + def test_timestamp_repr(self): # pre-1900 stamp = Timestamp('1850-01-01', tz='US/Eastern') diff --git a/pandas/tslib.pyx b/pandas/tslib.pyx index 649aa22e5e3ae..9a20c36638bce 100644 --- a/pandas/tslib.pyx +++ b/pandas/tslib.pyx @@ -687,7 +687,7 @@ class Timestamp(_Timestamp): # replace def validate(k, v): """ validate integers """ - if not isinstance(v, int): + if not is_integer_object(v): raise ValueError("value must be an integer, received " "{v} for {k}".format(v=type(v), k=k)) return v