Skip to content

Broaden read csv param types #630

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 7 commits into from
Apr 6, 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
13 changes: 13 additions & 0 deletions pandas-stubs/_typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@ ListLikeExceptSeriesAndStr = TypeVar(
"ListLikeExceptSeriesAndStr", MutableSequence, np.ndarray, tuple, "Index"
)
ListLikeU: TypeAlias = Sequence | np.ndarray | Series | Index
ListLikeHashable: TypeAlias = (
MutableSequence[HashableT] | np.ndarray | tuple[HashableT, ...] | range
)
StrLike: TypeAlias = str | np.str_
IndexIterScalar: TypeAlias = (
str
Expand All @@ -295,6 +298,16 @@ 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
)
# Scratch types for generics
S1 = TypeVar(
"S1",
Expand Down
35 changes: 8 additions & 27 deletions pandas-stubs/io/clipboards.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@ from typing import (
)

from pandas.core.frame import DataFrame
from pandas.core.indexes.base import Index
from pandas.core.series import Series

from pandas._typing import (
CompressionOptions,
CSVEngine,
CSVQuoting,
DtypeArg,
ListLikeHashable,
StorageOptions,
npt,
UsecolsArgType,
)

from pandas.io.parsers import TextFileReader
Expand All @@ -31,15 +30,9 @@ def read_clipboard(
*,
delimiter: str | None = ...,
header: int | Sequence[int] | Literal["infer"] | None = ...,
names: list[str] = ...,
names: ListLikeHashable | None = ...,
index_col: int | str | Sequence[str | int] | Literal[False] | None = ...,
usecols: list[str]
| Sequence[int]
| Series
| Index
| npt.NDArray
| Callable[[str], bool]
| None = ...,
usecols: UsecolsArgType = ...,
dtype: DtypeArg | defaultdict | None = ...,
engine: CSVEngine | None = ...,
converters: dict[int | str, Callable[[str], Any]] = ...,
Expand Down Expand Up @@ -94,15 +87,9 @@ def read_clipboard(
*,
delimiter: str | None = ...,
header: int | Sequence[int] | Literal["infer"] | None = ...,
names: list[str] = ...,
names: ListLikeHashable | None = ...,
index_col: int | str | Sequence[str | int] | Literal[False] | None = ...,
usecols: list[str]
| Sequence[int]
| Series
| Index
| npt.NDArray
| Callable[[str], bool]
| None = ...,
usecols: UsecolsArgType = ...,
dtype: DtypeArg | defaultdict | None = ...,
engine: CSVEngine | None = ...,
converters: dict[int | str, Callable[[str], Any]] = ...,
Expand Down Expand Up @@ -157,15 +144,9 @@ def read_clipboard(
*,
delimiter: str | None = ...,
header: int | Sequence[int] | Literal["infer"] | None = ...,
names: list[str] = ...,
names: ListLikeHashable | None = ...,
index_col: int | str | Sequence[str | int] | Literal[False] | None = ...,
usecols: list[str]
| Sequence[int]
| Series
| Index
| npt.NDArray
| Callable[[str], bool]
| None = ...,
usecols: UsecolsArgType = ...,
dtype: DtypeArg | defaultdict | None = ...,
engine: CSVEngine | None = ...,
converters: dict[int | str, Callable[[str], Any]] = ...,
Expand Down
26 changes: 10 additions & 16 deletions pandas-stubs/io/excel/_base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ from xlrd.book import Book
from pandas._typing import (
Dtype,
FilePath,
ListLikeHashable,
ReadBuffer,
StorageOptions,
UsecolsArgType,
WriteExcelBuffer,
)

Expand All @@ -40,9 +42,9 @@ def read_excel(
sheet_name: list[int | str] | None,
*,
header: int | Sequence[int] | None = ...,
names: list[str] | None = ...,
names: ListLikeHashable | None = ...,
index_col: int | Sequence[int] | None = ...,
usecols: Sequence[int] | Sequence[str] | Callable[[str], bool] | None = ...,
usecols: str | UsecolsArgType = ...,
dtype: str | Dtype | Mapping[str, str | Dtype] | None = ...,
engine: Literal["xlrd", "openpyxl", "odf", "pyxlsb"] | None = ...,
converters: Mapping[int | str, Callable[[object], object]] | None = ...,
Expand Down Expand Up @@ -78,9 +80,9 @@ def read_excel(
sheet_name: int | str = ...,
*,
header: int | Sequence[int] | None = ...,
names: list[str] | None = ...,
names: ListLikeHashable | None = ...,
index_col: int | Sequence[int] | None = ...,
usecols: Sequence[int] | Sequence[str] | Callable[[str], bool] | None = ...,
usecols: str | UsecolsArgType = ...,
dtype: str | Dtype | Mapping[str, str | Dtype] | None = ...,
engine: Literal["xlrd", "openpyxl", "odf", "pyxlsb"] | None = ...,
converters: Mapping[int | str, Callable[[object], object]] | None = ...,
Expand Down Expand Up @@ -155,13 +157,9 @@ class ExcelFile:
self,
sheet_name: list[int | str] | None,
header: int | Sequence[int] | None = ...,
names: list[str] | None = ...,
names: ListLikeHashable | None = ...,
index_col: int | Sequence[int] | None = ...,
usecols: str
| Sequence[int]
| Sequence[str]
| Callable[[str], bool]
| None = ...,
usecols: str | UsecolsArgType = ...,
converters: dict[int | str, Callable[[object], object]] | None = ...,
true_values: Iterable[Hashable] | None = ...,
false_values: Iterable[Hashable] | None = ...,
Expand All @@ -185,13 +183,9 @@ class ExcelFile:
self,
sheet_name: int | str,
header: int | Sequence[int] | None = ...,
names: list[str] | None = ...,
names: ListLikeHashable | None = ...,
index_col: int | Sequence[int] | None = ...,
usecols: str
| Sequence[int]
| Sequence[str]
| Callable[[str], bool]
| None = ...,
usecols: str | UsecolsArgType = ...,
converters: dict[int | str, Callable[[object], object]] | None = ...,
true_values: Iterable[Hashable] | None = ...,
false_values: Iterable[Hashable] | None = ...,
Expand Down
71 changes: 14 additions & 57 deletions pandas-stubs/io/parsers/readers.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ from typing import (
)

from pandas.core.frame import DataFrame
from pandas.core.indexes.base import Index
from pandas.core.series import Series
from typing_extensions import Self

from pandas._typing import (
Expand All @@ -26,9 +24,10 @@ from pandas._typing import (
CSVQuoting,
DtypeArg,
FilePath,
ListLikeHashable,
ReadCsvBuffer,
StorageOptions,
npt,
UsecolsArgType,
)

from pandas.io.common import IOHandles
Expand All @@ -40,16 +39,9 @@ def read_csv(
sep: str | None = ...,
delimiter: str | None = ...,
header: int | Sequence[int] | Literal["infer"] | None = ...,
names: list[str] | None = ...,
names: ListLikeHashable | None = ...,
index_col: int | str | Sequence[str | int] | Literal[False] | None = ...,
usecols: list[str]
| tuple[str, ...]
| Sequence[int]
| Series
| Index
| npt.NDArray
| Callable[[str], bool]
| None = ...,
usecols: UsecolsArgType = ...,
dtype: DtypeArg | defaultdict | None = ...,
engine: CSVEngine | None = ...,
converters: Mapping[int | str, Callable[[str], Any]]
Expand Down Expand Up @@ -106,16 +98,9 @@ def read_csv(
sep: str | None = ...,
delimiter: str | None = ...,
header: int | Sequence[int] | Literal["infer"] | None = ...,
names: list[str] | None = ...,
names: ListLikeHashable | None = ...,
index_col: int | str | Sequence[str | int] | Literal[False] | None = ...,
usecols: list[str]
| tuple[str, ...]
| Sequence[int]
| Series
| Index
| npt.NDArray
| Callable[[str], bool]
| None = ...,
usecols: UsecolsArgType = ...,
dtype: DtypeArg | defaultdict | None = ...,
engine: CSVEngine | None = ...,
converters: Mapping[int | str, Callable[[str], Any]]
Expand Down Expand Up @@ -172,16 +157,9 @@ def read_csv(
sep: str | None = ...,
delimiter: str | None = ...,
header: int | Sequence[int] | Literal["infer"] | None = ...,
names: list[str] | None = ...,
names: ListLikeHashable | None = ...,
index_col: int | str | Sequence[str | int] | Literal[False] | None = ...,
usecols: list[str]
| tuple[str, ...]
| Sequence[int]
| Series
| Index
| npt.NDArray
| Callable[[str], bool]
| None = ...,
usecols: UsecolsArgType = ...,
dtype: DtypeArg | defaultdict | None = ...,
engine: CSVEngine | None = ...,
converters: Mapping[int | str, Callable[[str], Any]]
Expand Down Expand Up @@ -238,16 +216,9 @@ def read_table(
sep: str | None = ...,
delimiter: str | None = ...,
header: int | Sequence[int] | Literal["infer"] | None = ...,
names: list[str] | None = ...,
names: ListLikeHashable | None = ...,
index_col: int | str | Sequence[str | int] | Literal[False] | None = ...,
usecols: list[str]
| tuple[str, ...]
| Sequence[int]
| Series
| Index
| npt.NDArray
| Callable[[str], bool]
| None = ...,
usecols: UsecolsArgType = ...,
dtype: DtypeArg | defaultdict | None = ...,
engine: CSVEngine | None = ...,
converters: Mapping[int | str, Callable[[str], Any]]
Expand Down Expand Up @@ -304,16 +275,9 @@ def read_table(
sep: str | None = ...,
delimiter: str | None = ...,
header: int | Sequence[int] | Literal["infer"] | None = ...,
names: list[str] | None = ...,
names: ListLikeHashable | None = ...,
index_col: int | str | Sequence[str | int] | Literal[False] | None = ...,
usecols: list[str]
| tuple[str, ...]
| Sequence[int]
| Series
| Index
| npt.NDArray
| Callable[[str], bool]
| None = ...,
usecols: UsecolsArgType = ...,
dtype: DtypeArg | defaultdict | None = ...,
engine: CSVEngine | None = ...,
converters: Mapping[int | str, Callable[[str], Any]]
Expand Down Expand Up @@ -370,16 +334,9 @@ def read_table(
sep: str | None = ...,
delimiter: str | None = ...,
header: int | Sequence[int] | Literal["infer"] | None = ...,
names: list[str] | None = ...,
names: ListLikeHashable | None = ...,
index_col: int | str | Sequence[str | int] | Literal[False] | None = ...,
usecols: list[str]
| tuple[str, ...]
| Sequence[int]
| Series
| Index
| npt.NDArray
| Callable[[str], bool]
| None = ...,
usecols: UsecolsArgType = ...,
dtype: DtypeArg | defaultdict | None = ...,
engine: CSVEngine | None = ...,
converters: Mapping[int | str, Callable[[str], Any]]
Expand Down
Loading