Skip to content

Commit 6cae23d

Browse files
sinhrksjreback
authored andcommitted
BUG: datetime64[us] arrays with NaT cannot be cast to DatetimeIndex
closes #13770 closes #9114 xref #13692
1 parent 7f02a46 commit 6cae23d

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

doc/source/whatsnew/v0.19.0.txt

+2
Original file line numberDiff line numberDiff line change
@@ -747,8 +747,10 @@ Bug Fixes
747747
- Bug in invalid datetime parsing in ``to_datetime`` and ``DatetimeIndex`` may raise ``TypeError`` rather than ``ValueError`` (:issue:`11169`, :issue:`11287`)
748748
- Bug in ``Index`` created with tz-aware ``Timestamp`` and mismatched ``tz`` option incorrectly coerces timezone (:issue:`13692`)
749749
- Bug in ``DatetimeIndex`` with nanosecond frequency does not include timestamp specified with ``end`` (:issue:`13672`)
750+
750751
- Bug in ``Index`` raises ``OutOfBoundsDatetime`` if ``datetime`` exceeds ``datetime64[ns]`` bounds, rather than coercing to ``object`` dtype (:issue:`13663`)
751752
- Bug in ``.value_counts`` raises ``OutOfBoundsDatetime`` if data exceeds ``datetime64[ns]`` bounds (:issue:`13663`)
753+
- Bug in ``DatetimeIndex`` may raise ``OutOfBoundsDatetime`` if input ``np.datetime64`` has other unit than ``ns`` (:issue:`9114`)
752754

753755
- Bug in ``Categorical.remove_unused_categories()`` changes ``.codes`` dtype to platform int (:issue:`13261`)
754756
- Bug in ``groupby`` with ``as_index=False`` returns all NaN's when grouping on multiple columns including a categorical one (:issue:`13204`)

pandas/tseries/tests/test_timeseries.py

+11
Original file line numberDiff line numberDiff line change
@@ -1595,6 +1595,17 @@ def test_dti_constructor_small_int(self):
15951595
arr = np.array([0, 10, 20], dtype=dtype)
15961596
tm.assert_index_equal(DatetimeIndex(arr), exp)
15971597

1598+
def test_dti_constructor_numpy_timeunits(self):
1599+
# GH 9114
1600+
base = pd.to_datetime(['2000-01-01T00:00', '2000-01-02T00:00', 'NaT'])
1601+
1602+
for dtype in ['datetime64[h]', 'datetime64[m]', 'datetime64[s]',
1603+
'datetime64[ms]', 'datetime64[us]', 'datetime64[ns]']:
1604+
values = base.values.astype(dtype)
1605+
1606+
tm.assert_index_equal(DatetimeIndex(values), base)
1607+
tm.assert_index_equal(to_datetime(values), base)
1608+
15981609
def test_normalize(self):
15991610
rng = date_range('1/1/2000 9:30', periods=10, freq='D')
16001611

0 commit comments

Comments
 (0)