Skip to content

Commit ae144bb

Browse files
sinhrksjreback
authored andcommitted
BUG: DatetimeIndex raises AttributeError on win
closes #13736
1 parent 622297c commit ae144bb

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

pandas/tseries/index.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,12 @@ def __new__(cls, data=None,
329329
subarr = tslib.cast_to_nanoseconds(data)
330330
else:
331331
subarr = data
332-
elif data.dtype == _INT64_DTYPE:
332+
else:
333+
# must be integer dtype otherwise
333334
if isinstance(data, Int64Index):
334335
raise TypeError('cannot convert Int64Index->DatetimeIndex')
336+
if data.dtype != _INT64_DTYPE:
337+
data = data.astype(np.int64)
335338
subarr = data.view(_NS_DTYPE)
336339

337340
if isinstance(subarr, DatetimeIndex):

pandas/tseries/tests/test_timeseries.py

+10
Original file line numberDiff line numberDiff line change
@@ -1520,6 +1520,16 @@ def test_dti_constructor_years_only(self):
15201520
(rng3, expected3), (rng4, expected4)]:
15211521
tm.assert_index_equal(rng, expected)
15221522

1523+
def test_dti_constructor_small_int(self):
1524+
# GH 13721
1525+
exp = DatetimeIndex(['1970-01-01 00:00:00.00000000',
1526+
'1970-01-01 00:00:00.00000001',
1527+
'1970-01-01 00:00:00.00000002'])
1528+
1529+
for dtype in [np.int64, np.int32, np.int16, np.int8]:
1530+
arr = np.array([0, 10, 20], dtype=dtype)
1531+
tm.assert_index_equal(DatetimeIndex(arr), exp)
1532+
15231533
def test_normalize(self):
15241534
rng = date_range('1/1/2000 9:30', periods=10, freq='D')
15251535

0 commit comments

Comments
 (0)