Skip to content
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
13 changes: 7 additions & 6 deletions pandas-stubs/io/parsers/readers.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ from pandas._typing import (
DtypeArg,
DtypeBackend,
FilePath,
HashableT,
ListLikeHashable,
ReadCsvBuffer,
StorageOptions,
Expand All @@ -44,7 +45,7 @@ def read_csv(
header: int | Sequence[int] | Literal["infer"] | None = ...,
names: ListLikeHashable | None = ...,
index_col: int | str | Sequence[str | int] | Literal[False] | None = ...,
usecols: UsecolsArgType = ...,
usecols: UsecolsArgType[HashableT] = ...,
dtype: DtypeArg | defaultdict | None = ...,
engine: CSVEngine | None = ...,
converters: (
Expand Down Expand Up @@ -108,7 +109,7 @@ def read_csv(
header: int | Sequence[int] | Literal["infer"] | None = ...,
names: ListLikeHashable | None = ...,
index_col: int | str | Sequence[str | int] | Literal[False] | None = ...,
usecols: UsecolsArgType = ...,
usecols: UsecolsArgType[HashableT] = ...,
dtype: DtypeArg | defaultdict | None = ...,
engine: CSVEngine | None = ...,
converters: (
Expand Down Expand Up @@ -172,7 +173,7 @@ def read_csv(
header: int | Sequence[int] | Literal["infer"] | None = ...,
names: ListLikeHashable | None = ...,
index_col: int | str | Sequence[str | int] | Literal[False] | None = ...,
usecols: UsecolsArgType = ...,
usecols: UsecolsArgType[HashableT] = ...,
dtype: DtypeArg | defaultdict | None = ...,
engine: CSVEngine | None = ...,
converters: (
Expand Down Expand Up @@ -236,7 +237,7 @@ def read_table(
header: int | Sequence[int] | Literal["infer"] | None = ...,
names: ListLikeHashable | None = ...,
index_col: int | str | Sequence[str | int] | Literal[False] | None = ...,
usecols: UsecolsArgType = ...,
usecols: UsecolsArgType[HashableT] = ...,
dtype: DtypeArg | defaultdict | None = ...,
engine: CSVEngine | None = ...,
converters: (
Expand Down Expand Up @@ -300,7 +301,7 @@ def read_table(
header: int | Sequence[int] | Literal["infer"] | None = ...,
names: ListLikeHashable | None = ...,
index_col: int | str | Sequence[str | int] | Literal[False] | None = ...,
usecols: UsecolsArgType = ...,
usecols: UsecolsArgType[HashableT] = ...,
dtype: DtypeArg | defaultdict | None = ...,
engine: CSVEngine | None = ...,
converters: (
Expand Down Expand Up @@ -364,7 +365,7 @@ def read_table(
header: int | Sequence[int] | Literal["infer"] | None = ...,
names: ListLikeHashable | None = ...,
index_col: int | str | Sequence[str | int] | Literal[False] | None = ...,
usecols: UsecolsArgType = ...,
usecols: UsecolsArgType[HashableT] = ...,
dtype: DtypeArg | defaultdict | None = ...,
engine: CSVEngine | None = ...,
converters: (
Expand Down
10 changes: 10 additions & 0 deletions tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,11 @@ def test_read_csv():
DataFrame,
)

def cols(x: str) -> bool:
return x in ["a", "b"]

pd.read_csv(path, usecols=cols)


def test_read_csv_iterator():
with ensure_clean() as path:
Expand Down Expand Up @@ -727,6 +732,11 @@ def test_types_read_csv() -> None:
pd.read_csv(path, names="abcd") # type: ignore[call-overload] # pyright: ignore[reportArgumentType]
pd.read_csv(path, usecols="abcd") # type: ignore[call-overload] # pyright: ignore[reportArgumentType]

def cols2(x: set[float]) -> bool:
return sum(x) < 1.0

pd.read_csv("file.csv", usecols=cols2) # type: ignore[type-var] # pyright: ignore[reportArgumentType]

tfr1 = pd.read_csv(path, nrows=2, iterator=True, chunksize=3)
check(assert_type(tfr1, TextFileReader), TextFileReader)
tfr1.close()
Expand Down