Skip to content

Commit 87c400b

Browse files
committed
DatetimeIndex get_loc validates date object
1 parent 3b1d4f1 commit 87c400b

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

pandas/core/indexes/datetimes.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -589,8 +589,11 @@ def get_loc(self, key, method=None, tolerance=None):
589589
if is_valid_nat_for_dtype(key, self.dtype):
590590
key = NaT
591591

592-
if isinstance(key, self._data._recognized_scalars):
593-
# needed to localize naive datetimes
592+
if any([
593+
isinstance(key, self._data._recognized_scalars) or
594+
isinstance(key, date)
595+
]):
596+
# needed to localize naive dates and datetimes
594597
key = self._maybe_cast_for_get_loc(key)
595598

596599
elif isinstance(key, str):

pandas/tests/indexes/datetimes/test_datetime.py

+7
Original file line numberDiff line numberDiff line change
@@ -402,3 +402,10 @@ def test_split_non_utc(self):
402402
result = np.split(indices, indices_or_sections=[])[0]
403403
expected = indices._with_freq(None)
404404
tm.assert_index_equal(result, expected)
405+
406+
def test_in_contains_date_object(self):
407+
# GH#35466
408+
d1 = date(2002, 9, 1)
409+
idx1 = DatetimeIndex([d1])
410+
assert d1 in idx1
411+
assert '2002-09-01' in idx1

0 commit comments

Comments
 (0)