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 all 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
94 changes: 46 additions & 48 deletions pandas-stubs/core/frame.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,21 @@ else:
@overload
def __getitem__(self, key: Hashable) -> Series: ...

_AstypeArgExt: TypeAlias = (
AstypeArg
| Literal[
"number",
"datetime64",
"datetime",
"integer",
"timedelta",
"timedelta64",
"datetimetz",
"datetime64[ns]",
]
)
_AstypeArgExtList: TypeAlias = _AstypeArgExt | list[_AstypeArgExt]

class DataFrame(NDFrame, OpsMixin, _GetItemHack):

__hash__: ClassVar[None] # type: ignore[assignment] # pyright: ignore[reportIncompatibleMethodOverride]
Expand Down Expand Up @@ -458,6 +473,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
def to_gbq(
self,
destination_table: str,
*,
project_id: str | None = ...,
chunksize: int | None = ...,
reauth: bool = ...,
Expand Down Expand Up @@ -524,6 +540,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
def to_parquet(
self,
path: FilePath | WriteBuffer[bytes],
*,
engine: ParquetEngine = ...,
compression: Literal["snappy", "gzip", "brotli", "lz4", "zstd"] | None = ...,
index: bool | None = ...,
Expand All @@ -535,6 +552,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
def to_parquet(
self,
path: None = ...,
*,
engine: ParquetEngine = ...,
compression: Literal["snappy", "gzip", "brotli", "lz4", "zstd"] | None = ...,
index: bool | None = ...,
Expand Down Expand Up @@ -564,6 +582,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
def to_html(
self,
buf: FilePath | WriteBuffer[str],
*,
columns: SequenceNotStr[Hashable] | Index | Series | None = ...,
col_space: ColspaceArgType | None = ...,
header: _bool = ...,
Expand Down Expand Up @@ -611,6 +630,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
def to_html(
self,
buf: None = ...,
*,
columns: Sequence[Hashable] | None = ...,
col_space: ColspaceArgType | None = ...,
header: _bool = ...,
Expand Down Expand Up @@ -746,27 +766,13 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
def eval(
self, expr: _str, *, inplace: Literal[False] = ..., **kwargs: Any
) -> Scalar | np.ndarray | Self | Series: ...
AstypeArgExt: TypeAlias = (
AstypeArg
| Literal[
"number",
"datetime64",
"datetime",
"integer",
"timedelta",
"timedelta64",
"datetimetz",
"datetime64[ns]",
]
)
AstypeArgExtList: TypeAlias = AstypeArgExt | list[AstypeArgExt]
@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 @@ -775,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 All @@ -810,6 +816,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
def reindex(
self,
labels: Axes | None = ...,
*,
index: Axes | None = ...,
columns: Axes | None = ...,
axis: Axis | None = ...,
Expand Down Expand Up @@ -1301,8 +1308,8 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
def pivot(
self,
*,
columns: IndexLabel,
index: IndexLabel = ...,
columns: IndexLabel = ...,
values: IndexLabel = ...,
) -> Self: ...
def pivot_table(
Expand All @@ -1320,11 +1327,18 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
) -> Self: ...
@overload
def stack(
self, level: IndexLabel = ..., dropna: _bool = ..., sort: _bool = ...
self,
level: IndexLabel = ...,
*,
future_stack: Literal[True],
) -> Self | Series: ...
@overload
def stack(
self, level: IndexLabel = ..., future_stack: _bool = ...
self,
level: IndexLabel = ...,
dropna: _bool = ...,
sort: _bool = ...,
future_stack: Literal[False] = ...,
) -> Self | Series: ...
def explode(
self, column: Sequence[Hashable], ignore_index: _bool = ...
Expand Down Expand Up @@ -1576,14 +1590,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
method: Literal["pearson", "kendall", "spearman"] = ...,
numeric_only: _bool = ...,
) -> Series: ...
@overload
def count(
self, axis: Axis = ..., numeric_only: _bool = ..., *, level: Level
) -> Self: ...
@overload
def count(
self, axis: Axis = ..., level: None = ..., numeric_only: _bool = ...
) -> Series: ...
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 @@ -1780,6 +1787,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
self,
start_time: _str | dt.time,
end_time: _str | dt.time,
inclusive: IntervalClosedType = ...,
axis: Axis | None = ...,
) -> Self: ...
@overload
Expand Down Expand Up @@ -1980,8 +1988,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
@final
def head(self, n: int = ...) -> Self: ...
@final
def infer_objects(self) -> Self: ...
# def info
def infer_objects(self, copy: _bool | None = ...) -> Self: ...
@overload
def interpolate(
self,
Expand Down Expand Up @@ -2077,15 +2084,13 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
self,
axis: Axis | None = ...,
skipna: _bool | None = ...,
level: None = ...,
numeric_only: _bool = ...,
**kwargs: Any,
) -> Series: ...
def min(
self,
axis: Axis | None = ...,
skipna: _bool | None = ...,
level: None = ...,
numeric_only: _bool = ...,
**kwargs: Any,
) -> Series: ...
Expand Down Expand Up @@ -2117,8 +2122,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
periods: int = ...,
fill_method: None = ...,
freq: DateOffset | dt.timedelta | _str | None = ...,
*,
axis: Axis = ...,
fill_value: Scalar | NAType | None = ...,
) -> Self: ...
def pop(self, item: _str) -> Series: ...
Expand All @@ -2133,7 +2136,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
self,
axis: Axis | None = ...,
skipna: _bool | None = ...,
level: None = ...,
numeric_only: _bool = ...,
min_count: int = ...,
**kwargs: Any,
Expand All @@ -2142,7 +2144,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
self,
axis: Axis | None = ...,
skipna: _bool = ...,
level: None = ...,
numeric_only: _bool = ...,
min_count: int = ...,
**kwargs: Any,
Expand Down Expand Up @@ -2305,18 +2306,16 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
self,
axis: Axis | None = ...,
skipna: _bool | None = ...,
level: None = ...,
ddof: int = ...,
numeric_only: _bool = ...,
**kwargs: Any,
) -> Series: ...
# Not actually positional, but used to handle removal of deprecated
def set_axis(self, labels, *, axis: Axis, copy: _bool = ...) -> Self: ...
def set_axis(self, labels, *, axis: Axis = ..., copy: _bool = ...) -> Self: ...
def skew(
self,
axis: Axis | None = ...,
skipna: _bool | None = ...,
level: None = ...,
numeric_only: _bool = ...,
**kwargs: Any,
) -> Series: ...
Expand All @@ -2326,7 +2325,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
self,
axis: Axis = ...,
skipna: _bool = ...,
level: None = ...,
ddof: int = ...,
numeric_only: _bool = ...,
**kwargs: Any,
Expand All @@ -2347,9 +2345,8 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
) -> Self: ...
def sum(
self,
axis: Axis | None = ...,
axis: Axis = ...,
skipna: _bool | None = ...,
level: None = ...,
numeric_only: _bool = ...,
min_count: int = ...,
**kwargs: Any,
Expand Down Expand Up @@ -2434,6 +2431,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
def to_string(
self,
buf: FilePath | WriteBuffer[str],
*,
columns: SequenceNotStr[Hashable] | Index | Series | None = ...,
col_space: int | list[int] | dict[HashableT, int] | None = ...,
header: _bool | list[_str] | tuple[str, ...] = ...,
Expand All @@ -2457,6 +2455,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
def to_string(
self,
buf: None = ...,
*,
columns: Sequence[Hashable] | Index | Series | None = ...,
col_space: int | list[int] | dict[Hashable, int] | None = ...,
header: _bool | Sequence[_str] = ...,
Expand Down Expand Up @@ -2513,9 +2512,8 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
) -> Self: ...
def var(
self,
axis: Axis | None = ...,
axis: Axis = ...,
skipna: _bool | None = ...,
level: None = ...,
ddof: int = ...,
numeric_only: _bool = ...,
**kwargs: Any,
Expand Down
4 changes: 3 additions & 1 deletion pandas-stubs/core/generic.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ class NDFrame(indexing.IndexingMixin):
def to_markdown(
self,
buf: FilePath | WriteBuffer[str],
mode: FileWriteMode | None = ...,
*,
mode: FileWriteMode = ...,
index: _bool = ...,
storage_options: StorageOptions = ...,
**kwargs: Any,
Expand All @@ -152,6 +153,7 @@ class NDFrame(indexing.IndexingMixin):
def to_markdown(
self,
buf: None = ...,
*,
mode: FileWriteMode | None = ...,
index: _bool = ...,
storage_options: StorageOptions = ...,
Expand Down
1 change: 0 additions & 1 deletion pandas-stubs/core/indexes/accessors.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ class _DatetimeOtherOps(Generic[_DTOtherOpsDateReturnType, _DTOtherOpsTimeReturn
@property
def timetz(self) -> _DTOtherOpsTimeReturnType: ...

class DatetimeAndPeriodProperties(_DatetimeFieldOps[Series[int]]): ...
class _DatetimeLikeOps(
_DatetimeFieldOps[_DTFieldOpsReturnType],
_DatetimeObjectOps[_DTFreqReturnType],
Expand Down
8 changes: 5 additions & 3 deletions pandas-stubs/core/indexes/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,9 @@ class Index(IndexOpsMixin[S1]):
@final
def is_(self, other) -> bool: ...
def __len__(self) -> int: ...
def __array__(self, dtype=...) -> np.ndarray: ...
def __array__(
self, dtype: _str | np.dtype = ..., copy: bool | None = ...
) -> np.ndarray: ...
def __array_wrap__(self, result, context=...): ...
@property
def dtype(self) -> DtypeObj: ...
Expand Down Expand Up @@ -313,9 +315,9 @@ class Index(IndexOpsMixin[S1]):
def names(self, names: Sequence[Hashable]) -> None: ...
def set_names(self, names, *, level=..., inplace: bool = ...): ...
@overload
def rename(self, name, inplace: Literal[False] = False) -> Self: ...
def rename(self, name, *, inplace: Literal[False] = False) -> Self: ...
@overload
def rename(self, name, inplace: Literal[True]) -> None: ...
def rename(self, name, *, inplace: Literal[True]) -> None: ...
@property
def nlevels(self) -> int: ...
def get_level_values(self, level: int | _str) -> Index: ...
Expand Down
1 change: 0 additions & 1 deletion pandas-stubs/core/indexes/category.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class CategoricalIndex(ExtensionIndex[S1], accessor.PandasDelegate):
self, dtype: DtypeArg = ..., copy: bool | None = ...
) -> np.ndarray: ...
def astype(self, dtype: DtypeArg, copy: bool = ...) -> Index: ...
def fillna(self, value=...): ...
@property
def is_unique(self) -> bool: ...
@property
Expand Down
1 change: 0 additions & 1 deletion pandas-stubs/core/indexes/datetimes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class DatetimeIndex(DatetimeTimedeltaMixin[Timestamp], DatetimeIndexProperties):
copy: bool = ...,
name: Hashable = ...,
) -> None: ...
def __array__(self, dtype=...) -> np.ndarray: ...
def __reduce__(self): ...
# various ignores needed for mypy, as we do want to restrict what can be used in
# arithmetic for these types
Expand Down
9 changes: 1 addition & 8 deletions pandas-stubs/core/indexes/interval.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,7 @@ class IntervalIndex(ExtensionIndex[IntervalT], IntervalMixin):
def memory_usage(self, deep: bool = ...) -> int: ...
@property
def is_overlapping(self) -> bool: ...
# Note: tolerance no effect. It is included in all get_loc so
# that signatures are consistent with base even though it is usually not used
def get_loc(
self,
key: Label,
method: FillnaOptions | Literal["nearest"] | None = ...,
tolerance=...,
) -> int | slice | npt.NDArray[np.bool_]: ...
def get_loc(self, key: Label) -> int | slice | npt.NDArray[np.bool_]: ...
@final
def get_indexer(
self,
Expand Down
Loading
Loading