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 13, 2018
1 parent fa231e8 commit 251ae24
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ 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 type(res) == slice or np.any(res + 1)
except (KeyError, TypeError, ValueError):
return False

Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/indexing/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,11 @@ def test_series_partial_set_period(self):
check_stacklevel=False):
result = ser.loc[keys]
tm.assert_series_equal(result, exp)

def test_monotone_DTI_indexing_bug(self):
# GH 19362

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

0 comments on commit 251ae24

Please sign in to comment.