Skip to content
Open
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
6 changes: 5 additions & 1 deletion pandas-stubs/_typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,11 @@ RandomState: TypeAlias = (
)

# dtypes
NpDtypeNoStr: TypeAlias = np.dtype[np.generic] | type[complex | bool | object]
if sys.version_info >= (3, 11):
NpDtypeNoStr: TypeAlias = np.dtype | type[complex | bool | object]
else:
NpDtypeNoStr: TypeAlias = np.dtype[Any] | type[complex | bool | object]

NpDtype: TypeAlias = str | NpDtypeNoStr | type[str]
Dtype: TypeAlias = ExtensionDtype | NpDtype

Expand Down
117 changes: 57 additions & 60 deletions pandas-stubs/core/generic.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ from collections.abc import (
Hashable,
Iterable,
Mapping,
MutableMapping,
Sequence,
)
import datetime as dt
Expand Down Expand Up @@ -40,13 +39,17 @@ from pandas._typing import (
ExcelWriterMergeCells,
FilePath,
FileWriteMode,
FloatFormatType,
FormattersType,
Frequency,
HashableT1,
HashableT2,
HDFCompLib,
IgnoreRaise,
IndexLabel,
Level,
ListLike,
NpDtype,
OpenFileErrors,
P,
StorageOptions,
Expand All @@ -56,9 +59,11 @@ from pandas._typing import (
TimeGrouperOrigin,
TimestampConvertibleTypes,
WriteBuffer,
WriteExcelBuffer,
np_ndarray,
)

from pandas.io.excel import ExcelWriter
from pandas.io.pytables import HDFStore
from pandas.io.sql import SQLTable

Expand Down Expand Up @@ -95,15 +100,17 @@ class NDFrame:
@final
def __round__(self, decimals: int = ...) -> Self: ...
@final
def __contains__(self, key) -> _bool: ...
def __contains__(self, key: Any) -> _bool: ...
@property
def empty(self) -> _bool: ...
__array_priority__: int = ...
def __array__(self, dtype=...) -> np_ndarray: ...
def __array__(
self, dtype: NpDtype | None = None, copy: _bool | None = None
) -> np_ndarray: ...
@final
def to_excel(
self,
excel_writer,
excel_writer: FilePath | WriteExcelBuffer | ExcelWriter,
sheet_name: _str = "Sheet1",
na_rep: _str = "",
float_format: _str | None = ...,
Expand Down Expand Up @@ -220,8 +227,8 @@ class NDFrame:
header: _bool | list[_str] = ...,
index: _bool = ...,
na_rep: _str = ...,
formatters=...,
float_format=...,
formatters: FormattersType | None = None,
float_format: FloatFormatType | None = None,
sparsify: _bool | None = ...,
index_names: _bool = ...,
bold_rows: _bool = ...,
Expand All @@ -245,8 +252,8 @@ class NDFrame:
header: _bool | list[_str] = ...,
index: _bool = ...,
na_rep: _str = ...,
formatters=...,
float_format=...,
formatters: FormattersType | None = None,
float_format: FloatFormatType | None = None,
sparsify: _bool | None = ...,
index_names: _bool = ...,
bold_rows: _bool = ...,
Expand Down Expand Up @@ -312,115 +319,113 @@ class NDFrame:
errors: OpenFileErrors = ...,
storage_options: StorageOptions = ...,
) -> _str: ...
@final
def __delitem__(self, idx: Hashable) -> None: ...
@overload
def drop(
self,
labels=...,
labels: Hashable | ListLike | None = None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
labels: Hashable | ListLike | None = None,
labels: Hashable | ListLike = None,

None ia also Hashable. Also applies to other cases in the changes.

*,
axis=...,
axis: Axis = 0,
index: None,
columns=...,
level=...,
inplace=...,
errors=...,
columns: Hashable | Iterable[Hashable] | None = None,
level: Level | None = None,
inplace: Literal[False] = False,
errors: IgnoreRaise = "raise",
) -> Never: ...
@overload
def drop(
self,
labels=...,
labels: Hashable | ListLike | None = None,
*,
axis=...,
index=...,
axis: Axis = 0,
index: Hashable | Sequence[Hashable] | Index | None = None,
columns: None,
level=...,
inplace=...,
errors=...,
level: Level | None = None,
inplace: Literal[False] = False,
errors: IgnoreRaise = "raise",
) -> Never: ...
@overload
def drop(
self,
labels: None,
*,
axis=...,
index=...,
columns=...,
level=...,
inplace=...,
errors=...,
axis: Axis = 0,
index: Hashable | Sequence[Hashable] | Index | None = None,
columns: Hashable | Iterable[Hashable] | None = None,
level: Level | None = None,
inplace: Literal[False] = False,
errors: IgnoreRaise = "raise",
) -> Never: ...
@overload
def drop(
self,
labels: None = None,
*,
axis: Axis = ...,
index: Hashable | Sequence[Hashable] | Index = ...,
axis: Axis = 0,
index: Hashable | Sequence[Hashable] | Index | None = None,
columns: Hashable | Iterable[Hashable],
level: Level | None = ...,
level: Level | None = None,
inplace: Literal[True],
errors: IgnoreRaise = ...,
errors: IgnoreRaise = "raise",
) -> None: ...
@overload
def drop(
self,
labels: None = None,
*,
axis: Axis = ...,
axis: Axis = 0,
index: Hashable | Sequence[Hashable] | Index,
columns: Hashable | Iterable[Hashable] = ...,
level: Level | None = ...,
columns: Hashable | Iterable[Hashable] | None = None,
level: Level | None = None,
inplace: Literal[True],
errors: IgnoreRaise = ...,
errors: IgnoreRaise = "raise",
) -> None: ...
@overload
def drop(
self,
labels: Hashable | Sequence[Hashable] | Index,
labels: Hashable | ListLike,
*,
axis: Axis = ...,
axis: Axis = 0,
index: None = None,
columns: None = None,
level: Level | None = ...,
level: Level | None = None,
inplace: Literal[True],
errors: IgnoreRaise = ...,
errors: IgnoreRaise = "raise",
) -> None: ...
@overload
def drop(
self,
labels: None = None,
*,
axis: Axis = ...,
index: Hashable | Sequence[Hashable] | Index = ...,
axis: Axis = 0,
index: Hashable | Sequence[Hashable] | Index | None = None,
columns: Hashable | Iterable[Hashable],
level: Level | None = ...,
level: Level | None = None,
inplace: Literal[False] = False,
errors: IgnoreRaise = ...,
errors: IgnoreRaise = "raise",
) -> Self: ...
@overload
def drop(
self,
labels: None = None,
*,
axis: Axis = ...,
axis: Axis = 0,
index: Hashable | Sequence[Hashable] | Index,
columns: Hashable | Iterable[Hashable] = ...,
level: Level | None = ...,
columns: Hashable | Iterable[Hashable] | None = None,
level: Level | None = None,
inplace: Literal[False] = False,
errors: IgnoreRaise = ...,
errors: IgnoreRaise = "raise",
) -> Self: ...
@overload
def drop(
self,
labels: Hashable | Sequence[Hashable] | Index,
labels: Hashable | ListLike,
*,
axis: Axis = ...,
axis: Axis = 0,
index: None = None,
columns: None = None,
level: Level | None = ...,
level: Level | None = None,
inplace: Literal[False] = False,
errors: IgnoreRaise = ...,
errors: IgnoreRaise = "raise",
) -> Self: ...
@overload
def pipe(
Expand All @@ -437,14 +442,6 @@ class NDFrame:
**kwargs: Any,
) -> T: ...
@final
def __finalize__(self, other, method=..., **kwargs: Any) -> Self: ...
@final
def __setattr__(self, name: _str, value) -> None: ...
@final
def __copy__(self, deep: _bool = ...) -> Self: ...
@final
def __deepcopy__(self, memo: MutableMapping[int, Any] | None = None) -> Self: ...
@final
def convert_dtypes(
self,
infer_objects: _bool = True,
Expand Down
13 changes: 4 additions & 9 deletions pandas-stubs/core/series.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ from pandas._typing import (
ListLikeU,
MaskType,
NaPosition,
NpDtype,
NsmallestNlargestKeep,
NumpyStrDtypeArg,
ObjectDtypeArg,
Expand Down Expand Up @@ -562,15 +563,9 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
def __array_ufunc__(
self, ufunc: Callable[..., Any], method: _str, *inputs: Any, **kwargs: Any
) -> Any: ...
if sys.version_info >= (3, 11):
def __array__(
self, dtype: _str | np.dtype = ..., copy: bool | None = ...
) -> np_1darray: ...
else:
def __array__(
self, dtype: _str | np.dtype[Any] = ..., copy: bool | None = ...
) -> np_1darray: ...

Comment on lines 565 to 573
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep it, it is needed for the pyright strict transition.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it ok to handle this within NpDType?

Copy link
Contributor

@cmp0xff cmp0xff Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NpDtype is different from str | np.dtype. It will take a separate PR to handle, I think.

def __array__(
self, dtype: NpDtype | None = None, copy: bool | None = None
) -> np_1darray: ...
@final
def __getattr__(self, name: _str) -> S1: ...

Expand Down
4 changes: 0 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,6 @@ ignore = [
# TODO: remove when window is fully typed
"ANN001", "ANN201", "ANN204", "ANN206",
]
"*generic.pyi" = [
# TODO: remove when generic.pyi is fully typed
"ANN001", "ANN201", "ANN204", "ANN206",
]
"*array*" = [
# TODO: remove when array is fully typed
"ANN001", "ANN201", "ANN204", "ANN206",
Expand Down