Skip to content

Improvements to arguments, types with stubtest #1294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jul 30, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 34 additions & 20 deletions pandas-stubs/core/frame.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ from pandas._typing import (

from pandas.io.formats.style import Styler
from pandas.plotting import PlotAccessor
from pandas.plotting._core import hist_frame

class _iLocIndexerFrame(_iLocIndexer, Generic[_T]):
@overload
Expand Down Expand Up @@ -309,7 +308,7 @@ else:
@overload
def __getitem__(self, key: Hashable) -> Series: ...

AstypeArgExt: TypeAlias = (
_AstypeArgExt: TypeAlias = (
AstypeArg
| Literal[
"number",
Expand All @@ -322,7 +321,7 @@ AstypeArgExt: TypeAlias = (
"datetime64[ns]",
]
)
AstypeArgExtList: TypeAlias = AstypeArgExt | list[AstypeArgExt]
_AstypeArgExtList: TypeAlias = _AstypeArgExt | list[_AstypeArgExt]

class DataFrame(NDFrame, OpsMixin, _GetItemHack):

Expand Down Expand Up @@ -769,11 +768,11 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
) -> Scalar | np.ndarray | Self | Series: ...
@overload
def select_dtypes(
self, include: StrDtypeArg, exclude: AstypeArgExtList | None = ...
self, include: StrDtypeArg, exclude: _AstypeArgExtList | None = ...
) -> Never: ...
@overload
def select_dtypes(
self, include: AstypeArgExtList | None, exclude: StrDtypeArg
self, include: _AstypeArgExtList | None, exclude: StrDtypeArg
) -> Never: ...
@overload
def select_dtypes(self, exclude: StrDtypeArg) -> Never: ...
Expand All @@ -782,19 +781,19 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
@overload
def select_dtypes(
self,
include: AstypeArgExtList,
exclude: AstypeArgExtList | None = ...,
include: _AstypeArgExtList,
exclude: _AstypeArgExtList | None = ...,
) -> Self: ...
@overload
def select_dtypes(
self,
include: AstypeArgExtList | None,
exclude: AstypeArgExtList,
include: _AstypeArgExtList | None,
exclude: _AstypeArgExtList,
) -> Self: ...
@overload
def select_dtypes(
self,
exclude: AstypeArgExtList,
exclude: _AstypeArgExtList,
) -> Self: ...
def insert(
self,
Expand Down Expand Up @@ -1330,17 +1329,15 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
def stack(
self,
level: IndexLabel = ...,
dropna: _bool = ...,
sort: _bool = ...,
future_stack: Literal[False] = ...,
future_stack: Literal[True] = ...,
) -> Self | Series: ...
@overload
def stack(
self,
level: IndexLabel = ...,
dropna: _NoDefaultDoNotUse = ...,
sort: _NoDefaultDoNotUse = ...,
future_stack: Literal[True] = ...,
dropna: _bool = ...,
sort: _bool = ...,
future_stack: Literal[False] = ...,
) -> Self | Series: ...
def explode(
self, column: Sequence[Hashable], ignore_index: _bool = ...
Expand Down Expand Up @@ -1376,9 +1373,9 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
**kwargs: Any,
) -> Self: ...
@overload
def aggregate(
def aggregate( # pyright: ignore[reportOverlappingOverload]
self,
func: AggFuncTypeBase | AggFuncTypeDictSeries = ...,
func: AggFuncTypeBase | AggFuncTypeDictSeries,
axis: Axis = ...,
**kwargs: Any,
) -> Series: ...
Expand Down Expand Up @@ -1592,7 +1589,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
method: Literal["pearson", "kendall", "spearman"] = ...,
numeric_only: _bool = ...,
) -> Series: ...
def count(self, axis: Axis = ..., numeric_only: _bool = ...) -> Self: ...
def count(self, axis: Axis = ..., numeric_only: _bool = ...) -> Series[int]: ...
def nunique(self, axis: Axis = ..., dropna: bool = ...) -> Series: ...
def idxmax(
self, axis: Axis = ..., skipna: _bool = ..., numeric_only: _bool = ...
Expand Down Expand Up @@ -1637,7 +1634,24 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
def isin(self, values: Iterable | Series | DataFrame | dict) -> Self: ...
@property
def plot(self) -> PlotAccessor: ...
hist = hist_frame
def hist(
self,
column: _str | list[_str] | None = ...,
by: _str | ListLike | None = ...,
grid: _bool = ...,
xlabelsize: float | str | None = ...,
xrot: float | None = ...,
ylabelsize: float | str | None = ...,
yrot: float | None = ...,
ax: PlotAxes | None = ...,
sharex: _bool = ...,
sharey: _bool = ...,
figsize: tuple[float, float] | None = ...,
layout: tuple[int, int] | None = ...,
bins: int | list = ...,
backend: _str | None = ...,
**kwargs: Any,
): ...
def boxplot(
self,
column: _str | list[_str] | None = ...,
Expand Down
10 changes: 5 additions & 5 deletions pandas-stubs/core/indexes/multi.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,28 @@ class MultiIndex(Index):
cls,
arrays: Sequence[Axes],
sortorder: int | None = ...,
names: SequenceNotStr[Hashable] | None = ...,
names: SequenceNotStr[Hashable] = ...,
) -> Self: ...
@classmethod
def from_tuples(
cls,
tuples: Iterable[tuple[Hashable, ...]],
sortorder: int | None = ...,
names: SequenceNotStr[Hashable] | None = ...,
names: SequenceNotStr[Hashable] = ...,
) -> Self: ...
@classmethod
def from_product(
cls,
iterables: Sequence[SequenceNotStr[Hashable] | pd.Series | pd.Index | range],
sortorder: int | None = ...,
names: SequenceNotStr[Hashable] | None = ...,
names: SequenceNotStr[Hashable] = ...,
) -> Self: ...
@classmethod
def from_frame(
cls,
df: pd.DataFrame,
sortorder: int | None = ...,
names: SequenceNotStr[Hashable] | None = ...,
names: SequenceNotStr[Hashable] = ...,
) -> Self: ...
@property
def shape(self): ...
Expand All @@ -77,7 +77,7 @@ class MultiIndex(Index):
def codes(self): ...
def set_codes(self, codes, *, level=..., verify_integrity: bool = ...): ...
def copy( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride] # pyrefly: ignore
self, names: SequenceNotStr[Hashable] = ..., deep: bool = ..., name: None = ...
self, names: SequenceNotStr[Hashable] = ..., deep: bool = ...
) -> Self: ...
def view(self, cls=...): ...
def __contains__(self, key) -> bool: ...
Expand Down
4 changes: 2 additions & 2 deletions pandas-stubs/core/series.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
self, i: Level = ..., j: Level = ..., copy: _bool = ...
) -> Series[S1]: ...
def reorder_levels(self, order: list) -> Series[S1]: ...
def explode(self, ignore_index: bool = ...) -> Series[S1]: ...
def explode(self, ignore_index: _bool = ...) -> Series[S1]: ...
def unstack(
self,
level: IndexLabel = ...,
Expand Down Expand Up @@ -1986,7 +1986,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
def expanding(
self,
min_periods: int = ...,
axis: Axes = ...,
axis: Literal[0] = ...,
method: CalculationMethod = ...,
) -> Expanding[Series]: ...
def floordiv(
Expand Down
20 changes: 0 additions & 20 deletions pandas-stubs/plotting/_core.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -435,23 +435,3 @@ class PlotAccessor:
) -> npt.NDArray[np.object_]: ...

density = kde

def hist_frame(
data: DataFrame,
column: Axes | None = None,
by=None,
grid: bool = True,
xlabelsize: int | None = None,
xrot: float | None = None,
ylabelsize: int | None = None,
yrot: float | None = None,
ax=None,
sharex: bool = False,
sharey: bool = False,
figsize: tuple[int, int] | None = None,
layout: tuple[int, int] | None = None,
bins: int | Sequence[int] = 10,
backend: str | None = None,
legend: bool = False,
**kwargs,
) -> Axes | list[Axes]: ...
15 changes: 7 additions & 8 deletions tests/series/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1520,14 +1520,13 @@ def test_types_bfill() -> None:

def test_types_ewm() -> None:
s1 = pd.Series([1, 2, 3])
if TYPE_CHECKING_INVALID_USAGE:
check(
assert_type(
s1.ewm(com=0.3, min_periods=0, adjust=False, ignore_na=True),
"ExponentialMovingWindow[pd.Series]",
),
ExponentialMovingWindow,
)
check(
assert_type(
s1.ewm(com=0.3, min_periods=0, adjust=False, ignore_na=True),
"ExponentialMovingWindow[pd.Series]",
),
ExponentialMovingWindow,
)
check(
assert_type(
s1.ewm(com=0.3, min_periods=0, adjust=False, ignore_na=True),
Expand Down
Loading