Skip to content

Commit d5770e2

Browse files
GHXXX Clean up from stubtest (#1267)
* GHXXX Clean up from stubtest * GHXXX PR feedback * GHXXX PR feedback * GHXXX Fix test * GHXXX More cleanup
1 parent 69cf85e commit d5770e2

File tree

9 files changed

+29
-56
lines changed

9 files changed

+29
-56
lines changed

pandas-stubs/core/frame.pyi

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1990,15 +1990,13 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
19901990
self,
19911991
axis: Axis | None = ...,
19921992
skipna: _bool | None = ...,
1993-
level: None = ...,
19941993
numeric_only: _bool = ...,
19951994
**kwargs: Any,
19961995
) -> Series: ...
19971996
def kurtosis(
19981997
self,
19991998
axis: Axis | None = ...,
20001999
skipna: _bool | None = ...,
2001-
level: None = ...,
20022000
numeric_only: _bool = ...,
20032001
**kwargs: Any,
20042002
) -> Series: ...
@@ -2042,15 +2040,13 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
20422040
self,
20432041
axis: Axis | None = ...,
20442042
skipna: _bool | None = ...,
2045-
level: None = ...,
20462043
numeric_only: _bool = ...,
20472044
**kwargs: Any,
20482045
) -> Series: ...
20492046
def mean(
20502047
self,
20512048
axis: Axis | None = ...,
20522049
skipna: _bool | None = ...,
2053-
level: None = ...,
20542050
numeric_only: _bool = ...,
20552051
**kwargs: Any,
20562052
) -> Series: ...

pandas-stubs/core/groupby/groupby.pyi

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ from collections.abc import (
33
Hashable,
44
Iterable,
55
Iterator,
6-
Mapping,
76
Sequence,
87
)
98
import datetime as dt
@@ -21,7 +20,6 @@ from pandas.core.base import SelectionMixin
2120
from pandas.core.frame import DataFrame
2221
from pandas.core.groupby import (
2322
generic,
24-
ops,
2523
)
2624
from pandas.core.groupby.indexing import (
2725
GroupByIndexingMixin,
@@ -75,24 +73,13 @@ from pandas._typing import (
7573

7674
from pandas.plotting import PlotAccessor
7775

78-
_KeysArgType: TypeAlias = (
79-
Hashable
80-
| list[Hashable]
81-
| Callable[[Hashable], Hashable]
82-
| list[Callable[[Hashable], Hashable]]
83-
| Mapping[Hashable, Hashable]
84-
)
85-
8676
_ResamplerGroupBy: TypeAlias = (
8777
DatetimeIndexResamplerGroupby[NDFrameT]
8878
| PeriodIndexResamplerGroupby[NDFrameT]
8979
| TimedeltaIndexResamplerGroupby[NDFrameT]
9080
)
9181

9282
class GroupBy(BaseGroupBy[NDFrameT]):
93-
as_index: bool
94-
sort: bool
95-
observed: bool
9683
def __getattr__(self, attr: str) -> Any: ...
9784
def apply(self, func: Callable | str, *args, **kwargs) -> NDFrameT: ...
9885
@final
@@ -356,11 +343,6 @@ class GroupByPlot(PlotAccessor, Generic[_GroupByT]):
356343
# def __getattr__(self, name: str): ...
357344

358345
class BaseGroupBy(SelectionMixin[NDFrameT], GroupByIndexingMixin):
359-
axis: AxisInt
360-
grouper: ops.BaseGrouper
361-
keys: _KeysArgType | None
362-
level: IndexLabel | None
363-
group_keys: bool
364346
@final
365347
def __len__(self) -> int: ...
366348
@final

pandas-stubs/core/indexes/base.pyi

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ from pandas._typing import (
4848
DropKeep,
4949
DtypeArg,
5050
DtypeObj,
51-
FillnaOptions,
5251
HashableT,
5352
Label,
5453
Level,
5554
MaskType,
55+
NaPosition,
5656
ReindexMethod,
5757
SliceType,
5858
TimedeltaDtypeArg,
@@ -313,7 +313,6 @@ class Index(IndexOpsMixin[S1]):
313313
def rename(self, name, inplace: Literal[True]) -> None: ...
314314
@property
315315
def nlevels(self) -> int: ...
316-
def sortlevel(self, level=..., ascending: bool = ..., sort_remaining=...): ...
317316
def get_level_values(self, level: int | _str) -> Index: ...
318317
def droplevel(self, level: Level | list[Level] = ...): ...
319318
@property
@@ -353,12 +352,7 @@ class Index(IndexOpsMixin[S1]):
353352
def symmetric_difference(
354353
self, other: list[S1] | Self, result_name: Hashable = ..., sort=...
355354
) -> Self: ...
356-
def get_loc(
357-
self,
358-
key: Label,
359-
method: FillnaOptions | Literal["nearest"] | None = ...,
360-
tolerance=...,
361-
) -> int | slice | np_ndarray_bool: ...
355+
def get_loc(self, key: Label) -> int | slice | np_ndarray_bool: ...
362356
def get_indexer(
363357
self, target, method: ReindexMethod | None = ..., limit=..., tolerance=...
364358
): ...
@@ -400,7 +394,14 @@ class Index(IndexOpsMixin[S1]):
400394
def identical(self, other) -> bool: ...
401395
def asof(self, label): ...
402396
def asof_locs(self, where, mask): ...
403-
def sort_values(self, return_indexer: bool = ..., ascending: bool = ...): ...
397+
def sort_values(
398+
self,
399+
*,
400+
return_indexer: bool = ...,
401+
ascending: bool = ...,
402+
na_position: NaPosition = ...,
403+
key: Callable[[Index], Index] | None = None,
404+
): ...
404405
def sort(self, *args, **kwargs) -> None: ...
405406
def argsort(self, *args, **kwargs): ...
406407
def get_indexer_non_unique(self, target): ...

pandas-stubs/core/indexes/category.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ class CategoricalIndex(ExtensionIndex[S1], accessor.PandasDelegate):
3333
@property
3434
def values(self): ...
3535
def __contains__(self, key) -> bool: ...
36-
def __array__(self, dtype=...) -> np.ndarray: ...
36+
def __array__(
37+
self, dtype: DtypeArg = ..., copy: bool | None = ...
38+
) -> np.ndarray: ...
3739
def astype(self, dtype: DtypeArg, copy: bool = ...) -> Index: ...
3840
def fillna(self, value=...): ...
3941
@property

pandas-stubs/core/indexes/multi.pyi

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ from collections.abc import (
44
Iterable,
55
Sequence,
66
)
7-
from typing import (
8-
overload,
9-
)
7+
from typing import overload
108

119
import numpy as np
1210
import pandas as pd
@@ -20,7 +18,9 @@ from pandas._typing import (
2018
Dtype,
2119
DtypeArg,
2220
HashableT,
21+
Level,
2322
MaskType,
23+
NaPosition,
2424
SequenceNotStr,
2525
np_ndarray_anyint,
2626
np_ndarray_bool,
@@ -140,7 +140,11 @@ class MultiIndex(Index):
140140
def swaplevel(self, i: int = ..., j: int = ...): ...
141141
def reorder_levels(self, order): ...
142142
def sortlevel(
143-
self, level: int = ..., ascending: bool = ..., sort_remaining: bool = ...
143+
self,
144+
level: Level | Sequence[Level] = ...,
145+
ascending: bool = ...,
146+
sort_remaining: bool = ...,
147+
na_position: NaPosition = ...,
144148
): ...
145149
def get_indexer(self, target, method=..., limit=..., tolerance=...): ...
146150
def get_indexer_non_unique(self, target): ...
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
from pandas.core.interchange.dataframe_protocol import DataFrame as DataFrame
2-
from pandas.core.interchange.from_dataframe import from_dataframe as from_dataframe

pandas-stubs/core/resample.pyi

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,12 @@ from typing import (
1111
import numpy as np
1212
from pandas import (
1313
DataFrame,
14-
DatetimeIndex,
15-
Index,
16-
PeriodIndex,
1714
Series,
1815
Timedelta,
19-
TimedeltaIndex,
2016
)
2117
from pandas.core.groupby.generic import SeriesGroupBy
2218
from pandas.core.groupby.groupby import BaseGroupBy
2319
from pandas.core.groupby.grouper import Grouper
24-
from pandas.core.groupby.ops import BinGrouper
2520
from typing_extensions import (
2621
Self,
2722
TypeAlias,
@@ -62,10 +57,6 @@ _SeriesGroupByFuncArgs: TypeAlias = (
6257
)
6358

6459
class Resampler(BaseGroupBy[NDFrameT]):
65-
grouper: BinGrouper # pyright: ignore[reportIncompatibleVariableOverride] # pyrefly: ignore # variance incompatibility
66-
binner: DatetimeIndex | TimedeltaIndex | PeriodIndex
67-
exclusions: frozenset[Hashable]
68-
ax: Index
6960
def __getattr__(self, attr: str) -> SeriesGroupBy: ...
7061
@overload
7162
def aggregate(
@@ -123,8 +114,12 @@ class Resampler(BaseGroupBy[NDFrameT]):
123114
def prod(self, numeric_only: bool = ..., min_count: int = ...) -> NDFrameT: ...
124115
def min(self, numeric_only: bool = ..., min_count: int = ...) -> NDFrameT: ...
125116
def max(self, numeric_only: bool = ..., min_count: int = ...) -> NDFrameT: ...
126-
def first(self, numeric_only: bool = ..., min_count: int = ...) -> NDFrameT: ...
127-
def last(self, numeric_only: bool = ..., min_count: int = ...) -> NDFrameT: ...
117+
def first(
118+
self, numeric_only: bool = ..., min_count: int = ..., skipna: bool = ...
119+
) -> NDFrameT: ...
120+
def last(
121+
self, numeric_only: bool = ..., min_count: int = ..., skipna: bool = ...
122+
) -> NDFrameT: ...
128123
def median(self, numeric_only: bool = ...) -> NDFrameT: ...
129124
def mean(self, numeric_only: bool = ...) -> NDFrameT: ...
130125
def std(self, ddof: int = ..., numeric_only: bool = ...) -> NDFrameT: ...

tests/test_groupby.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import numpy as np
1313
from pandas import (
1414
DataFrame,
15-
DatetimeIndex,
1615
Index,
1716
Series,
1817
Timedelta,
@@ -74,7 +73,6 @@ def test_frame_groupby_resample() -> None:
7473

7574
# props
7675
check(assert_type(GB_DF.resample("ME").obj, DataFrame), DataFrame)
77-
check(assert_type(GB_DF.resample("ME").ax, Index), DatetimeIndex)
7876

7977
# agg funcs
8078
with pytest_warns_bounded(
@@ -329,7 +327,6 @@ def test_series_groupby_resample() -> None:
329327

330328
# props
331329
check(assert_type(GB_S.resample("ME").obj, "Series[float]"), Series, float)
332-
check(assert_type(GB_S.resample("ME").ax, Index), DatetimeIndex)
333330

334331
# agg funcs
335332
check(assert_type(GB_S.resample("ME").sum(), "Series[float]"), Series, float)

tests/test_resampler.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
import pandas as pd
99
from pandas import (
1010
DataFrame,
11-
DatetimeIndex,
12-
Index,
1311
Series,
1412
date_range,
1513
)
@@ -38,7 +36,6 @@
3836

3937
def test_props() -> None:
4038
check(assert_type(DF.resample("ME").obj, DataFrame), DataFrame)
41-
check(assert_type(DF.resample("ME").ax, Index), DatetimeIndex)
4239

4340

4441
def test_iter() -> None:
@@ -53,7 +50,9 @@ def test_agg_funcs() -> None:
5350
check(assert_type(DF.resample("ME").min(), DataFrame), DataFrame)
5451
check(assert_type(DF.resample("ME").max(), DataFrame), DataFrame)
5552
check(assert_type(DF.resample("ME").first(), DataFrame), DataFrame)
53+
check(assert_type(DF.resample("ME").first(skipna=False), DataFrame), DataFrame)
5654
check(assert_type(DF.resample("ME").last(), DataFrame), DataFrame)
55+
check(assert_type(DF.resample("ME").last(skipna=False), DataFrame), DataFrame)
5756
check(assert_type(DF.resample("ME").mean(), DataFrame), DataFrame)
5857
check(assert_type(DF.resample("ME").sum(), DataFrame), DataFrame)
5958
check(assert_type(DF.resample("ME").median(), DataFrame), DataFrame)
@@ -271,7 +270,6 @@ def f(val: Series) -> Series:
271270

272271
def test_props_series() -> None:
273272
check(assert_type(S.resample("ME").obj, Series), Series)
274-
check(assert_type(S.resample("ME").ax, Index), DatetimeIndex)
275273

276274

277275
def test_iter_series() -> None:

0 commit comments

Comments
 (0)