Skip to content

Commit 251ae24

Browse files
committed
BUG: fixes indexing with monotonic decreasing DTI (#19362)
1 parent fa231e8 commit 251ae24

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

pandas/core/indexes/datetimelike.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ def _format_with_header(self, header, **kwargs):
342342
def __contains__(self, key):
343343
try:
344344
res = self.get_loc(key)
345-
return is_scalar(res) or type(res) == slice or np.any(res)
345+
return is_scalar(res) or type(res) == slice or np.any(res + 1)
346346
except (KeyError, TypeError, ValueError):
347347
return False
348348

pandas/tests/indexing/test_datetime.py

+8
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,11 @@ def test_series_partial_set_period(self):
252252
check_stacklevel=False):
253253
result = ser.loc[keys]
254254
tm.assert_series_equal(result, exp)
255+
256+
def test_monotone_DTI_indexing_bug(self):
257+
# GH 19362
258+
259+
df = pd.DataFrame({'A': [1, 2, 3]},
260+
index=pd.date_range('20170101',
261+
periods=3)[::-1])
262+
df.loc['2017-01-03']

0 commit comments

Comments
 (0)