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 eb437ea
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime, time, timedelta, tzinfo
from datetime import datetime, date, time, timedelta, tzinfo
from typing import Optional, Union
import warnings

Expand Down Expand Up @@ -152,7 +152,7 @@ class DatetimeArray(dtl.DatetimeLikeArrayMixin, dtl.TimelikeOps, dtl.DatelikeOps

_typ = "datetimearray"
_scalar_type = Timestamp
_recognized_scalars = (datetime, np.datetime64)
_recognized_scalars = (datetime, np.datetime64, date)
_is_recognized_dtype = is_datetime64_any_dtype

# define my properties & methods for delegation
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 eb437ea

Please sign in to comment.