Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pandas/tseries/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
10 changes: 10 additions & 0 deletions pandas/tseries/tests/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down