Skip to content
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

Sync Usecols with pandas #793

Merged
merged 1 commit into from
Oct 7, 2023
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
25 changes: 17 additions & 8 deletions pandas-stubs/_typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ from typing import (
Any,
Literal,
Protocol,
SupportsIndex,
TypedDict,
TypeVar,
overload,
)

import numpy as np
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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():
Expand Down