diff --git a/pandas-stubs/core/indexes/datetimes.pyi b/pandas-stubs/core/indexes/datetimes.pyi index 615cb098e..41dc9bb34 100644 --- a/pandas-stubs/core/indexes/datetimes.pyi +++ b/pandas-stubs/core/indexes/datetimes.pyi @@ -97,6 +97,7 @@ class DatetimeIndex( # type: ignore[misc] def tzinfo(self) -> tzinfo | None: ... @property def dtype(self) -> np.dtype | DatetimeTZDtype: ... + def intersection(self, other: DatetimeIndex | list) -> DatetimeIndex: ... def date_range( start: str | DateAndDatetimeLike | None = ..., diff --git a/tests/test_indexes.py b/tests/test_indexes.py index fa4557600..6ecd996c7 100644 --- a/tests/test_indexes.py +++ b/tests/test_indexes.py @@ -978,3 +978,12 @@ def test_index_constructors(): # to specify all the possible dtype options. For right now, we will leave the # test here as a reminder that we would like this to be seen as incorrect usage. pd.Index(flist, dtype=np.float16) + + +def test_datetimeindex_intersection(): + idx1 = pd.DatetimeIndex(["2022-01-01", "2022-01-02"]) + idx2 = pd.DatetimeIndex(["2022-01-02", "2022-01-03"]) + + result = idx1.intersection(idx2) + + check(assert_type(result, pd.DatetimeIndex), pd.DatetimeIndex)