Skip to content

Commit 6000c5b

Browse files
jdeschenesjreback
authored andcommitted
Fix for #16909(DeltatimeIndex.get_loc is not working on np.deltatime64 data type) (#16912)
1 parent 4ca9fcd commit 6000c5b

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

doc/source/whatsnew/v0.21.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ Indexing
155155
- When called with a null slice (e.g. ``df.iloc[:]``), the ``.iloc`` and ``.loc`` indexers return a shallow copy of the original object. Previously they returned the original object. (:issue:`13873`).
156156
- When called on an unsorted ``MultiIndex``, the ``loc`` indexer now will raise ``UnsortedIndexError`` only if proper slicing is used on non-sorted levels (:issue:`16734`).
157157
- Fixes regression in 0.20.3 when indexing with a string on a ``TimedeltaIndex`` (:issue:`16896`).
158+
- Fixed ``TimedeltaIndex.get_loc`` handling of ``np.timedelta64`` inputs (:issue:`16909`).
158159

159160
I/O
160161
^^^

pandas/core/indexes/timedeltas.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
_ensure_int64)
1616
from pandas.core.dtypes.missing import isnull
1717
from pandas.core.dtypes.generic import ABCSeries
18-
from pandas.core.common import _maybe_box, _values_from_object, is_bool_indexer
18+
from pandas.core.common import _maybe_box, _values_from_object
1919

2020
from pandas.core.indexes.base import Index
2121
from pandas.core.indexes.numeric import Int64Index
@@ -682,7 +682,7 @@ def get_loc(self, key, method=None, tolerance=None):
682682
-------
683683
loc : int
684684
"""
685-
if is_bool_indexer(key) or is_timedelta64_dtype(key):
685+
if is_list_like(key):
686686
raise TypeError
687687

688688
if isnull(key):

pandas/tests/indexes/timedeltas/test_timedelta.py

+3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ def test_get_loc(self):
6666
for method, loc in [('pad', 1), ('backfill', 2), ('nearest', 1)]:
6767
assert idx.get_loc('1 day 1 hour', method) == loc
6868

69+
# GH 16909
70+
assert idx.get_loc(idx[1].to_timedelta64()) == 1
71+
6972
# GH 16896
7073
assert idx.get_loc('0 days') == 0
7174

0 commit comments

Comments
 (0)