Skip to content

Commit

Permalink
DatetimeIndex get_loc validates date object
Browse files Browse the repository at this point in the history
  • Loading branch information
knabben committed Jul 30, 2020
1 parent 3b1d4f1 commit 87c400b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,8 +589,11 @@ def get_loc(self, key, method=None, tolerance=None):
if is_valid_nat_for_dtype(key, self.dtype):
key = NaT

if isinstance(key, self._data._recognized_scalars):
# needed to localize naive datetimes
if any([
isinstance(key, self._data._recognized_scalars) or
isinstance(key, date)
]):
# needed to localize naive dates and datetimes
key = self._maybe_cast_for_get_loc(key)

elif isinstance(key, str):
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/indexes/datetimes/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,3 +402,10 @@ def test_split_non_utc(self):
result = np.split(indices, indices_or_sections=[])[0]
expected = indices._with_freq(None)
tm.assert_index_equal(result, expected)

def test_in_contains_date_object(self):
# GH#35466
d1 = date(2002, 9, 1)
idx1 = DatetimeIndex([d1])
assert d1 in idx1
assert '2002-09-01' in idx1

0 comments on commit 87c400b

Please sign in to comment.