Skip to content

Commit 42fa72f

Browse files
committed
DatetimeIndex get_loc validates date object
1 parent 3b1d4f1 commit 42fa72f

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

pandas/core/arrays/datetimes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from datetime import datetime, time, timedelta, tzinfo
1+
from datetime import date, datetime, time, timedelta, tzinfo
22
from typing import Optional, Union
33
import warnings
44

@@ -152,7 +152,7 @@ class DatetimeArray(dtl.DatetimeLikeArrayMixin, dtl.TimelikeOps, dtl.DatelikeOps
152152

153153
_typ = "datetimearray"
154154
_scalar_type = Timestamp
155-
_recognized_scalars = (datetime, np.datetime64)
155+
_recognized_scalars = (datetime, np.datetime64, date)
156156
_is_recognized_dtype = is_datetime64_any_dtype
157157

158158
# define my properties & methods for delegation

pandas/tests/arithmetic/test_datetime64.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@ def test_compare_zerodim(self, tz_naive_fixture, box_with_array):
6868
4.0,
6969
object(),
7070
timedelta(days=2),
71-
# GH#19800, GH#19301 datetime.date comparison raises to
72-
# match DatetimeIndex/Timestamp. This also matches the behavior
73-
# of stdlib datetime.datetime
74-
datetime(2001, 1, 1).date(),
7571
# GH#19301 None and NaN are *not* cast to NaT for comparisons
7672
None,
7773
np.nan,

pandas/tests/indexes/datetimes/test_datetime.py

Lines changed: 7 additions & 0 deletions
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)