Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
get_loc should now work for np.timedelta64 data type.
  • Loading branch information
Jean-Mathieu Deschenes committed Jul 13, 2017
1 parent 9d13227 commit 5ab186c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.21.0.txt
Expand Up @@ -155,7 +155,7 @@ Indexing

- 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`).
- 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`).

- Fixed ``TimedeltaIndex.get_loc`` ``for np.timedelta64`` data type(:issue:`16909`).

I/O
^^^
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/timedeltas.py
Expand Up @@ -682,7 +682,7 @@ def get_loc(self, key, method=None, tolerance=None):
-------
loc : int
"""
if is_bool_indexer(key) or is_timedelta64_dtype(key):
if is_list_like(key):
raise TypeError

if isnull(key):
Expand Down
2 changes: 2 additions & 0 deletions pandas/tests/indexes/timedeltas/test_timedelta.py
Expand Up @@ -66,6 +66,8 @@ def test_get_loc(self):
for method, loc in [('pad', 1), ('backfill', 2), ('nearest', 1)]:
assert idx.get_loc('1 day 1 hour', method) == loc

assert idx.get_loc(idx[1].to_timedelta64()) == 1

def test_get_loc_nat(self):
tidx = TimedeltaIndex(['1 days 01:00:00', 'NaT', '2 days 01:00:00'])

Expand Down

0 comments on commit 5ab186c

Please sign in to comment.