diff --git a/pandas/tseries/index.py b/pandas/tseries/index.py index d448ca9878b99..64f156f4b044c 100644 --- a/pandas/tseries/index.py +++ b/pandas/tseries/index.py @@ -329,9 +329,12 @@ def __new__(cls, data=None, subarr = tslib.cast_to_nanoseconds(data) else: subarr = data - elif data.dtype == _INT64_DTYPE: + else: + # must be integer dtype otherwise if isinstance(data, Int64Index): raise TypeError('cannot convert Int64Index->DatetimeIndex') + if data.dtype != _INT64_DTYPE: + data = data.astype(np.int64) subarr = data.view(_NS_DTYPE) if isinstance(subarr, DatetimeIndex): diff --git a/pandas/tseries/tests/test_timeseries.py b/pandas/tseries/tests/test_timeseries.py index 9c97749c87103..2a9696503eaa5 100644 --- a/pandas/tseries/tests/test_timeseries.py +++ b/pandas/tseries/tests/test_timeseries.py @@ -1520,6 +1520,16 @@ def test_dti_constructor_years_only(self): (rng3, expected3), (rng4, expected4)]: tm.assert_index_equal(rng, expected) + def test_dti_constructor_small_int(self): + # GH 13721 + exp = DatetimeIndex(['1970-01-01 00:00:00.00000000', + '1970-01-01 00:00:00.00000001', + '1970-01-01 00:00:00.00000002']) + + for dtype in [np.int64, np.int32, np.int16, np.int8]: + arr = np.array([0, 10, 20], dtype=dtype) + tm.assert_index_equal(DatetimeIndex(arr), exp) + def test_normalize(self): rng = date_range('1/1/2000 9:30', periods=10, freq='D')