Skip to content

Commit 6141754

Browse files
authored
COMPAT: py2.7 compat for Timestamp.replace (#15030)
xref statsmodels/statsmodels#3349
1 parent b81e500 commit 6141754

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

doc/source/whatsnew/v0.20.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ Bug Fixes
305305

306306
- Bug in ``Series`` construction with a datetimetz (:issue:`14928`)
307307

308-
308+
- Bug in compat for passing long integers to ``Timestamp.replace`` (:issue:`15030`)
309309

310310

311311

pandas/tseries/tests/test_timeseries.py

+11
Original file line numberDiff line numberDiff line change
@@ -1883,6 +1883,17 @@ def test_timestamp_date_out_of_range(self):
18831883
self.assertRaises(ValueError, DatetimeIndex, ['1400-01-01'])
18841884
self.assertRaises(ValueError, DatetimeIndex, [datetime(1400, 1, 1)])
18851885

1886+
def test_compat_replace(self):
1887+
# https://github.com/statsmodels/statsmodels/issues/3349
1888+
# replace should take ints/longs for compat
1889+
1890+
for f in [compat.long, int]:
1891+
result = date_range(Timestamp('1960-04-01 00:00:00',
1892+
freq='QS-JAN'),
1893+
periods=f(76),
1894+
freq='QS-JAN')
1895+
self.assertEqual(len(result), 76)
1896+
18861897
def test_timestamp_repr(self):
18871898
# pre-1900
18881899
stamp = Timestamp('1850-01-01', tz='US/Eastern')

pandas/tslib.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ class Timestamp(_Timestamp):
687687
# replace
688688
def validate(k, v):
689689
""" validate integers """
690-
if not isinstance(v, int):
690+
if not is_integer_object(v):
691691
raise ValueError("value must be an integer, received "
692692
"{v} for {k}".format(v=type(v), k=k))
693693
return v

0 commit comments

Comments
 (0)