Skip to content

Commit 6d02ca8

Browse files
authored
type *core/base.pyi, remove SelectionMixin (#1567)
* remove SelectionMixin * remove `.obj` test
1 parent 4339fbb commit 6d02ca8

File tree

7 files changed

+6
-50
lines changed

7 files changed

+6
-50
lines changed

pandas-stubs/core/base.pyi

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from collections.abc import (
2-
Hashable,
32
Iterator,
43
Sequence,
54
)
@@ -11,7 +10,6 @@ from typing import (
1110
Protocol,
1211
TypeAlias,
1312
TypeVar,
14-
final,
1513
overload,
1614
type_check_only,
1715
)
@@ -42,7 +40,6 @@ from pandas._typing import (
4240
GenericT_co,
4341
Just,
4442
ListLike,
45-
NDFrameT,
4643
Scalar,
4744
SupportsDType,
4845
np_1darray,
@@ -54,22 +51,12 @@ from pandas._typing import (
5451
np_ndarray_float,
5552
np_ndarray_td,
5653
)
57-
from pandas.util._decorators import cache_readonly
5854

5955
T_INTERVAL_NP = TypeVar("T_INTERVAL_NP", bound=np.bytes_ | np.str_)
6056

6157
class NoNewAttributesMixin:
6258
def __setattr__(self, key: str, value: Any) -> None: ...
6359

64-
class SelectionMixin(Generic[NDFrameT]):
65-
obj: NDFrameT
66-
exclusions: frozenset[Hashable]
67-
@final
68-
@cache_readonly
69-
def ndim(self) -> int: ...
70-
def __getitem__(self, key): ...
71-
def aggregate(self, func, *args: Any, **kwargs: Any): ...
72-
7360
class IndexOpsMixin(OpsMixin, Generic[S1, GenericT_co]):
7461
__array_priority__: int = ...
7562
@property

pandas-stubs/core/groupby/groupby.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ from typing import (
1818
)
1919

2020
import numpy as np
21-
from pandas.core.base import SelectionMixin
2221
from pandas.core.frame import DataFrame
2322
from pandas.core.groupby import generic
2423
from pandas.core.groupby.indexing import (
@@ -350,7 +349,7 @@ class GroupByPlot(PlotAccessor, Generic[_GroupByT]):
350349
# def __call__(self, *args: Any, **kwargs: Any): ...
351350
# def __getattr__(self, name: str): ...
352351

353-
class BaseGroupBy(SelectionMixin[NDFrameT], GroupByIndexingMixin):
352+
class BaseGroupBy(GroupByIndexingMixin, Generic[NDFrameT]):
354353
@final
355354
def __len__(self) -> int: ...
356355
@final

pandas-stubs/core/window/rolling.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ from collections.abc import (
77
import datetime as dt
88
from typing import (
99
Any,
10+
Generic,
1011
overload,
1112
)
1213

@@ -15,7 +16,6 @@ from pandas import (
1516
Index,
1617
Series,
1718
)
18-
from pandas.core.base import SelectionMixin
1919
from pandas.core.indexers import BaseIndexer
2020
from typing_extensions import Self
2121

@@ -34,7 +34,7 @@ from pandas._typing import (
3434
WindowingRankType,
3535
)
3636

37-
class BaseWindow(SelectionMixin[NDFrameT]):
37+
class BaseWindow(Generic[NDFrameT]):
3838
on: str | Index | None
3939
closed: IntervalClosedType | None
4040
step: int | None

pyproject.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,6 @@ ignore = [
217217
# TODO: remove when array is fully typed
218218
"ANN001", "ANN201", "ANN204", "ANN206",
219219
]
220-
"*core/base.pyi" = [
221-
# TODO: remove when core/base.pyi is fully typed
222-
"ANN001", "ANN201", "ANN204", "ANN206",
223-
]
224220
"*excel/_base.pyi" = [
225221
# TODO: remove when excel/_base.pyi is fully typed
226222
"ANN001", "ANN201", "ANN204", "ANN206",

tests/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def check(
139139
elif isinstance(actual, pd.Index):
140140
value = actual[index_to_check_for_type]
141141
elif isinstance(actual, BaseGroupBy):
142-
value = actual.obj
142+
value = actual.obj # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue]
143143
elif hasattr(actual, "__iter__"):
144144
value = next(
145145
iter(actual) # pyright: ignore[reportArgumentType,reportCallIssue]

tests/test_groupby.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@ def test_frame_groupby_resample() -> None:
7070
DataFrame,
7171
)
7272

73-
# props
74-
check(assert_type(GB_DF.resample("ME").obj, DataFrame), DataFrame)
75-
7673
# agg funcs
7774
with pytest_warns_bounded(
7875
FutureWarning,
@@ -312,9 +309,6 @@ def test_series_groupby_resample() -> None:
312309
Series,
313310
)
314311

315-
# props
316-
check(assert_type(GB_S.resample("ME").obj, "Series[float]"), Series, float)
317-
318312
# agg funcs
319313
check(assert_type(GB_S.resample("ME").sum(), "Series[float]"), Series, float)
320314
check(assert_type(GB_S.resample("ME").prod(), "Series[float]"), Series, float)
@@ -471,7 +465,6 @@ def test_frame_groupby_rolling() -> None:
471465
)
472466

473467
# props
474-
check(assert_type(GB_DF.rolling(1).obj, DataFrame), DataFrame)
475468
check(assert_type(GB_DF.rolling(1).on, str | Index | None), type(None))
476469
check(assert_type(GB_DF.rolling(1).method, Literal["single", "table"]), str)
477470
if PD_LTE_23:
@@ -596,9 +589,6 @@ def test_series_groupby_rolling() -> None:
596589
Series,
597590
)
598591

599-
# props
600-
check(assert_type(GB_S.rolling(1).obj, "Series[float]"), Series, float)
601-
602592
# agg funcs
603593
check(assert_type(GB_S.rolling(1).sum(), "Series[float]"), Series, float)
604594
check(assert_type(GB_S.rolling(1).min(), "Series[float]"), Series, float)
@@ -666,7 +656,6 @@ def test_frame_groupby_expanding() -> None:
666656
)
667657

668658
# props
669-
check(assert_type(GB_DF.expanding(1).obj, DataFrame), DataFrame)
670659
check(assert_type(GB_DF.expanding(1).on, str | Index | None), type(None))
671660
check(assert_type(GB_DF.expanding(1).method, Literal["single", "table"]), str)
672661
if PD_LTE_23:
@@ -795,9 +784,6 @@ def test_series_groupby_expanding() -> None:
795784
Series,
796785
)
797786

798-
# props
799-
check(assert_type(GB_S.expanding(1).obj, "Series[float]"), Series, float)
800-
801787
# agg funcs
802788
check(assert_type(GB_S.expanding(1).sum(), "Series[float]"), Series, float)
803789
check(assert_type(GB_S.expanding(1).min(), "Series[float]"), Series, float)
@@ -865,7 +851,6 @@ def test_frame_groupby_ewm() -> None:
865851
)
866852

867853
# props
868-
check(assert_type(GB_DF.ewm(1).obj, DataFrame), DataFrame)
869854
check(assert_type(GB_DF.ewm(1).on, str | Index | None), type(None))
870855
check(assert_type(GB_DF.ewm(1).method, Literal["single", "table"]), str)
871856
if PD_LTE_23:
@@ -973,9 +958,6 @@ def test_series_groupby_ewm() -> None:
973958
Series,
974959
)
975960

976-
# props
977-
check(assert_type(GB_S.ewm(1).obj, "Series[float]"), Series, float)
978-
979961
# agg funcs
980962
check(assert_type(GB_S.ewm(1).sum(), "Series[float]"), Series, float)
981963
check(assert_type(GB_S.ewm(1).mean(), "Series[float]"), Series, float)

tests/test_resampler.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@
4040
_AggRetType = DataFrame | Series
4141

4242

43-
def test_props() -> None:
44-
check(assert_type(DF.resample("ME").obj, DataFrame), DataFrame)
45-
46-
4743
def test_iter() -> None:
4844
assert_type(iter(DF.resample("ME")), Iterator[tuple[Hashable, DataFrame]])
4945
for v in DF.resample("ME"):
@@ -203,7 +199,7 @@ def j(
203199
kw: tuple[int],
204200
) -> DataFrame:
205201
assert isinstance(res, DatetimeIndexResampler)
206-
return res.obj
202+
return DataFrame({"a": [1, 2, 3]})
207203

208204
check(
209205
assert_type(DF.resample("ME").pipe(j, 1, [1.0], arg2="hi", kw=(1,)), DataFrame),
@@ -263,7 +259,7 @@ def j(
263259

264260
def k(x: int, t: "DatetimeIndexResampler[DataFrame]") -> DataFrame:
265261
assert isinstance(x, int)
266-
return t.obj
262+
return DataFrame({"a": [1, 2, 3]})
267263

268264
check(assert_type(DF.resample("ME").pipe((k, "t"), 1), DataFrame), DataFrame)
269265

@@ -281,10 +277,6 @@ def f(val: Series) -> Series:
281277
check(assert_type(DF.resample("ME").transform(f), DataFrame), DataFrame)
282278

283279

284-
def test_props_series() -> None:
285-
check(assert_type(S.resample("ME").obj, Series), Series)
286-
287-
288280
def test_iter_series() -> None:
289281
for v in S.resample("ME"):
290282
check(assert_type(v, tuple[Hashable, Series]), tuple)

0 commit comments

Comments
 (0)