From da947ebcc09e3c55a98d1718f9c446ae7fbdf45b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CCandace?= Date: Sun, 16 Jul 2023 15:18:11 -0700 Subject: [PATCH 1/4] Fix DatetimeIndex.intersection() return type --- pandas-stubs/core/indexes/datetimes.pyi | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas-stubs/core/indexes/datetimes.pyi b/pandas-stubs/core/indexes/datetimes.pyi index 615cb098e..7f76b0e3c 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) -> DatetimeIndex: ... def date_range( start: str | DateAndDatetimeLike | None = ..., From 4649a054053948b22fd70bc8929bf31c79a6fbfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CCandace?= Date: Sun, 16 Jul 2023 15:32:57 -0700 Subject: [PATCH 2/4] added a test --- tests/test_indexes.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/test_indexes.py b/tests/test_indexes.py index fa4557600..4a30c2e90 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) + + assert_type(result, pd.DatetimeIndex) \ No newline at end of file From 20b80842fbc6afd1b8d4639df125c1d505b083d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CCandace?= Date: Sun, 16 Jul 2023 22:03:40 -0700 Subject: [PATCH 3/4] fixed signature error --- pandas-stubs/core/indexes/datetimes.pyi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas-stubs/core/indexes/datetimes.pyi b/pandas-stubs/core/indexes/datetimes.pyi index 7f76b0e3c..0f18765b2 100644 --- a/pandas-stubs/core/indexes/datetimes.pyi +++ b/pandas-stubs/core/indexes/datetimes.pyi @@ -17,6 +17,7 @@ from pandas import ( Timedelta, TimedeltaIndex, Timestamp, + Index ) from pandas.core.indexes.accessors import DatetimeIndexProperties from pandas.core.indexes.base import ( @@ -97,7 +98,7 @@ class DatetimeIndex( # type: ignore[misc] def tzinfo(self) -> tzinfo | None: ... @property def dtype(self) -> np.dtype | DatetimeTZDtype: ... - def intersection(self, other: DatetimeIndex) -> DatetimeIndex: ... + def intersection(self, other: Index | list) -> DatetimeIndex: ... def date_range( start: str | DateAndDatetimeLike | None = ..., From b5a11d65476701c896b584e4ec68cecdfe33bca2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CCandace?= Date: Mon, 17 Jul 2023 08:44:25 -0700 Subject: [PATCH 4/4] fixed issues --- pandas-stubs/core/indexes/datetimes.pyi | 3 +-- tests/test_indexes.py | 8 ++++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/pandas-stubs/core/indexes/datetimes.pyi b/pandas-stubs/core/indexes/datetimes.pyi index 0f18765b2..41dc9bb34 100644 --- a/pandas-stubs/core/indexes/datetimes.pyi +++ b/pandas-stubs/core/indexes/datetimes.pyi @@ -17,7 +17,6 @@ from pandas import ( Timedelta, TimedeltaIndex, Timestamp, - Index ) from pandas.core.indexes.accessors import DatetimeIndexProperties from pandas.core.indexes.base import ( @@ -98,7 +97,7 @@ class DatetimeIndex( # type: ignore[misc] def tzinfo(self) -> tzinfo | None: ... @property def dtype(self) -> np.dtype | DatetimeTZDtype: ... - def intersection(self, other: Index | list) -> DatetimeIndex: ... + 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 4a30c2e90..6ecd996c7 100644 --- a/tests/test_indexes.py +++ b/tests/test_indexes.py @@ -979,11 +979,11 @@ def test_index_constructors(): # 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']) +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) - assert_type(result, pd.DatetimeIndex) \ No newline at end of file + check(assert_type(result, pd.DatetimeIndex), pd.DatetimeIndex)