Skip to content

Commit

Permalink
BUG: fixes indexing with monotonic decreasing DTI (#19362)
Browse files Browse the repository at this point in the history
  • Loading branch information
mapehe committed Apr 14, 2018
1 parent d104ecd commit 3c84724
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,8 @@ def _format_with_header(self, header, **kwargs):
def __contains__(self, key):
try:
res = self.get_loc(key)
return is_scalar(res) or type(res) == slice or np.any(res)
return is_scalar(res) or isinstance(res, slice) or \
(is_list_like(res) and len(res))
except (KeyError, TypeError, ValueError):
return False

Expand Down
11 changes: 11 additions & 0 deletions pandas/tests/indexes/datetimes/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,3 +368,14 @@ def test_factorize_dst(self):
def test_unique(self, arr, expected):
result = arr.unique()
tm.assert_index_equal(result, expected)

def test_monotone_DTI_indexing_bug(self):
# GH 19362

df = pd.DataFrame({'A': [1, 2, 3]},
index=pd.date_range('20170101',
periods=3)[::-1])
expected = pd.DataFrame({'A': 1},
index=pd.date_range('20170103',
periods=1))
tm.assert_frame_equal(df.loc['2017-01-03'], expected)

0 comments on commit 3c84724

Please sign in to comment.