From 926450bad41e3f153188f730338b96a7de717ba7 Mon Sep 17 00:00:00 2001 From: Jan Lodewijk <160859694+janlodewijk@users.noreply.github.com> Date: Thu, 6 Feb 2025 22:46:42 +0100 Subject: [PATCH 1/5] Update series.pyi, tackling issue #1101 Imported Index from pandas and Changed keys method: def keys(self) -> Index: ... --- pandas-stubs/core/series.pyi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas-stubs/core/series.pyi b/pandas-stubs/core/series.pyi index 8b78c6d16..271b005f2 100644 --- a/pandas-stubs/core/series.pyi +++ b/pandas-stubs/core/series.pyi @@ -34,6 +34,7 @@ from pandas import ( PeriodDtype, Timedelta, Timestamp, + Index, ) from pandas.core.api import ( Int8Dtype as Int8Dtype, @@ -652,7 +653,7 @@ class Series(IndexOpsMixin[S1], NDFrame): ) -> _str: ... def to_xarray(self) -> xr.DataArray: ... def items(self) -> Iterable[tuple[Hashable, S1]]: ... - def keys(self) -> list: ... + def keys(self) -> Index: ... @overload def to_dict(self, *, into: type[dict] = ...) -> dict[Any, S1]: ... @overload From ed85e9a0f520abfe48e645f0f436673559331abe Mon Sep 17 00:00:00 2001 From: Jan Lodewijk <160859694+janlodewijk@users.noreply.github.com> Date: Fri, 7 Feb 2025 11:26:38 +0100 Subject: [PATCH 2/5] Update test_series.py Add a test for issue # 1101 --- tests/test_series.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_series.py b/tests/test_series.py index f0dbe8019..c79bacd3f 100644 --- a/tests/test_series.py +++ b/tests/test_series.py @@ -3541,6 +3541,13 @@ def test_series_dict() -> None: ) +def test_series_keys_type() -> None: + # GH 1101 + if TYPE_CHECKING: + s = pd.Series([1, 2, 3]) + assert_type(s.keys(), pd.Index) + + def test_series_int_float() -> None: # pyright infers mixtures of int and float in a list as list[int | float] check(assert_type(pd.Series([1, 2, 3]), "pd.Series[int]"), pd.Series, np.integer) From 35bd06f97811bed5e9e7b221a71a904f006c1095 Mon Sep 17 00:00:00 2001 From: Jan Lodewijk <160859694+janlodewijk@users.noreply.github.com> Date: Fri, 7 Feb 2025 16:17:53 +0100 Subject: [PATCH 3/5] Update tests/test_series.py Following the pandas pattern. Co-authored-by: Irv Lustig --- tests/test_series.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/test_series.py b/tests/test_series.py index c79bacd3f..0fffc9ab8 100644 --- a/tests/test_series.py +++ b/tests/test_series.py @@ -3543,9 +3543,8 @@ def test_series_dict() -> None: def test_series_keys_type() -> None: # GH 1101 - if TYPE_CHECKING: - s = pd.Series([1, 2, 3]) - assert_type(s.keys(), pd.Index) + s = pd.Series([1, 2, 3]) + check(assert_type(s.keys(), pd.Index), pd.Index) def test_series_int_float() -> None: From 0f1ce5e736d0c44b708eae55dd206041bfec4aa3 Mon Sep 17 00:00:00 2001 From: janlodewijk <160859694+janlodewijk@users.noreply.github.com> Date: Sat, 8 Feb 2025 14:37:10 +0100 Subject: [PATCH 4/5] Fix import issue in series.pyi to resolve Ruff error --- pandas-stubs/core/series.pyi | 3 +-- test | 2 ++ tests/test_series.py | 6 ++++++ 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 test diff --git a/pandas-stubs/core/series.pyi b/pandas-stubs/core/series.pyi index 271b005f2..76cd646f3 100644 --- a/pandas-stubs/core/series.pyi +++ b/pandas-stubs/core/series.pyi @@ -30,11 +30,11 @@ from matplotlib.axes import ( ) import numpy as np from pandas import ( + Index, Period, PeriodDtype, Timedelta, Timestamp, - Index, ) from pandas.core.api import ( Int8Dtype as Int8Dtype, @@ -59,7 +59,6 @@ from pandas.core.indexes.accessors import ( TimedeltaProperties, TimestampProperties, ) -from pandas.core.indexes.base import Index from pandas.core.indexes.category import CategoricalIndex from pandas.core.indexes.datetimes import DatetimeIndex from pandas.core.indexes.interval import IntervalIndex diff --git a/test b/test new file mode 100644 index 000000000..e446f3ac8 --- /dev/null +++ b/test @@ -0,0 +1,2 @@ + test +ind abc \ No newline at end of file diff --git a/tests/test_series.py b/tests/test_series.py index f0dbe8019..e9fa5c8e6 100644 --- a/tests/test_series.py +++ b/tests/test_series.py @@ -3541,6 +3541,12 @@ def test_series_dict() -> None: ) +def test_series_keys_type() -> None: + # GH 1101 + s = pd.Series([1, 2, 3]) + check(assert_type(s.keys(), pd.Index), pd.Index) + + def test_series_int_float() -> None: # pyright infers mixtures of int and float in a list as list[int | float] check(assert_type(pd.Series([1, 2, 3]), "pd.Series[int]"), pd.Series, np.integer) From 22f75a8aadd64f9d625bf7e8788ec6ebf951eb03 Mon Sep 17 00:00:00 2001 From: janlodewijk <160859694+janlodewijk@users.noreply.github.com> Date: Mon, 10 Feb 2025 18:47:41 +0100 Subject: [PATCH 5/5] Delete test --- test | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 test diff --git a/test b/test deleted file mode 100644 index e446f3ac8..000000000 --- a/test +++ /dev/null @@ -1,2 +0,0 @@ - test -ind abc \ No newline at end of file