diff --git a/pandas-stubs/_typing.pyi b/pandas-stubs/_typing.pyi index 17f8f7f2..ad6ae4d4 100644 --- a/pandas-stubs/_typing.pyi +++ b/pandas-stubs/_typing.pyi @@ -13,8 +13,10 @@ from typing import ( Any, Literal, Protocol, + SupportsIndex, TypedDict, TypeVar, + overload, ) import numpy as np @@ -421,6 +423,20 @@ class WriteExcelBuffer(WriteBuffer[bytes], Protocol): FilePath: TypeAlias = str | PathLike[str] +_T_co = TypeVar("_T_co", covariant=True) + +class SequenceNotStr(Protocol[_T_co]): + @overload + def __getitem__(self, index: SupportsIndex, /) -> _T_co: ... + @overload + def __getitem__(self, index: slice, /) -> Sequence[_T_co]: ... + def __contains__(self, value: object, /) -> bool: ... + def __len__(self) -> int: ... + def __iter__(self) -> Iterator[_T_co]: ... + def index(self, value: Any, /, start: int = 0, stop: int = ...) -> int: ... + def count(self, value: Any, /) -> int: ... + def __reversed__(self) -> Iterator[_T_co]: ... + IndexLabel: TypeAlias = Hashable | Sequence[Hashable] Label: TypeAlias = Hashable | None Level: TypeAlias = Hashable | int @@ -492,14 +508,7 @@ np_ndarray_str: TypeAlias = npt.NDArray[np.str_] IndexType: TypeAlias = slice | np_ndarray_anyint | Index | list[int] | Series[int] MaskType: TypeAlias = Series[bool] | np_ndarray_bool | list[bool] UsecolsArgType: TypeAlias = ( - MutableSequence[str] - | tuple[str, ...] - | Sequence[int] - | Series - | Index - | np.ndarray - | Callable[[HashableT], bool] - | None + SequenceNotStr[Hashable] | range | AnyArrayLike | Callable[[HashableT], bool] | None ) # Scratch types for generics diff --git a/tests/test_io.py b/tests/test_io.py index 52881916..7e981a07 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -279,7 +279,7 @@ def test_clipboard(): ) if TYPE_CHECKING_INVALID_USAGE: pd.read_clipboard(names="abcd") # type: ignore[call-overload] # pyright: ignore[reportGeneralTypeIssues] - pd.read_clipboard(usecols="abcd") # type: ignore[arg-type] # pyright: ignore[reportGeneralTypeIssues] + pd.read_clipboard(usecols="abcd") # type: ignore[call-overload] # pyright: ignore[reportGeneralTypeIssues] def test_clipboard_iterator(): @@ -667,7 +667,7 @@ def test_types_read_csv() -> None: if TYPE_CHECKING_INVALID_USAGE: pd.read_csv(path, names="abcd") # type: ignore[call-overload] # pyright: ignore[reportGeneralTypeIssues] - pd.read_csv(path, usecols="abcd") # type: ignore[arg-type] # pyright: ignore[reportGeneralTypeIssues] + pd.read_csv(path, usecols="abcd") # type: ignore[call-overload] # pyright: ignore[reportGeneralTypeIssues] tfr1: TextFileReader = pd.read_csv(path, nrows=2, iterator=True, chunksize=3) tfr1.close() @@ -801,7 +801,7 @@ def test_read_table(): ) if TYPE_CHECKING_INVALID_USAGE: pd.read_table(path, names="abcd") # type: ignore[call-overload] # pyright: ignore[reportGeneralTypeIssues] - pd.read_table(path, usecols="abcd") # type: ignore[arg-type] # pyright: ignore[reportGeneralTypeIssues] + pd.read_table(path, usecols="abcd") # type: ignore[call-overload] # pyright: ignore[reportGeneralTypeIssues] def test_read_table_iterator():