Skip to content

Commit 6583c57

Browse files
committed
BUG: Remove special-casing for Python date objects in DatetimeIndex
1 parent 610868f commit 6583c57

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

pandas/tests/frame/indexing/test_indexing.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1882,15 +1882,20 @@ def test_add_new_column_infer_string():
18821882

18831883
def test_datetime_indexer_consistency_pyarrow_date32():
18841884
# GH#62158
1885+
pytest.importorskip("pyarrow", minversion="13.0.0")
18851886
ser = Series(["2016-01-01"], dtype="date32[pyarrow]")
18861887
ser3 = ser.astype("datetime64[ns]")
18871888
dti = Index(ser3)
1888-
# All should be consistent
1889-
assert dti.get_loc(ser[0]) == 0
1890-
tm.assert_numpy_array_equal(dti.get_indexer(ser.values), np.array([0]))
1891-
tm.assert_numpy_array_equal(
1892-
dti.get_indexer(ser.values.astype(object)), np.array([0])
1893-
)
1889+
1890+
with pytest.raises(KeyError):
1891+
dti.get_loc(ser[0])
1892+
1893+
# get_indexer returns -1 for both Arrow array and object-cast
1894+
result = dti.get_indexer(ser.values)
1895+
tm.assert_numpy_array_equal(result, np.array([-1], dtype=np.intp))
1896+
1897+
result_obj = dti.get_indexer(ser.values.astype(object))
1898+
tm.assert_numpy_array_equal(result_obj, np.array([-1], dtype=np.intp))
18941899

18951900

18961901
class TestSetitemValidation:

pandas/tests/series/test_arithmetic.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -767,10 +767,21 @@ def test_align_date_objects_with_datetimeindex(self):
767767

768768
result = ts + ts2
769769
result2 = ts2 + ts
770-
expected = ts + ts[5:]
771-
expected.index = expected.index._with_freq(None)
772-
tm.assert_series_equal(result, expected)
773-
tm.assert_series_equal(result2, expected)
770+
771+
date_labels = [x.date() for x in rng[5:]]
772+
expected_index = Index(list(rng) + date_labels, dtype=object)
773+
774+
# Length and index checks
775+
assert len(result) == 35
776+
tm.assert_index_equal(result.index, expected_index)
777+
tm.assert_index_equal(result2.index, expected_index)
778+
assert result.index.dtype == object
779+
780+
# All NaN because there are no matching labels now
781+
assert result.isna().all()
782+
assert result2.isna().all()
783+
784+
tm.assert_series_equal(result, result2)
774785

775786

776787
class TestNamePreservation:

0 commit comments

Comments
 (0)