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

TYP: read_csv's usecols #55330

Merged
merged 4 commits into from
Oct 4, 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
9 changes: 9 additions & 0 deletions pandas/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,3 +509,12 @@ def closed(self) -> bool:

# Offsets
OffsetCalendar = Union[np.busdaycalendar, "AbstractHolidayCalendar"]

# read_csv: usecols
UsecolsArgType = Union[
SequenceNotStr[Hashable],
range,
AnyArrayLike,
Callable[[HashableT], bool],
None,
]
54 changes: 12 additions & 42 deletions pandas/io/parsers/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@
DtypeArg,
DtypeBackend,
FilePath,
HashableT,
IndexLabel,
ReadCsvBuffer,
Self,
StorageOptions,
UsecolsArgType,
)
_doc_read_csv_and_table = (
r"""
Expand Down Expand Up @@ -142,7 +142,7 @@
Note: ``index_col=False`` can be used to force pandas to *not* use the first
column as the index, e.g., when you have a malformed file with delimiters at
the end of each line.
usecols : list of Hashable or Callable, optional
usecols : Sequence of Hashable or Callable, optional
Subset of columns to select, denoted either by column labels or column indices.
If list-like, all elements must either
be positional (i.e. integer indices into the document columns) or strings
Expand Down Expand Up @@ -645,10 +645,7 @@ def read_csv(
header: int | Sequence[int] | None | Literal["infer"] = ...,
names: Sequence[Hashable] | None | lib.NoDefault = ...,
index_col: IndexLabel | Literal[False] | None = ...,
usecols: list[HashableT]
| tuple[HashableT]
| Callable[[Hashable], bool]
| None = ...,
usecols: UsecolsArgType = ...,
dtype: DtypeArg | None = ...,
engine: CSVEngine | None = ...,
converters: Mapping[Hashable, Callable] | None = ...,
Expand Down Expand Up @@ -707,10 +704,7 @@ def read_csv(
header: int | Sequence[int] | None | Literal["infer"] = ...,
names: Sequence[Hashable] | None | lib.NoDefault = ...,
index_col: IndexLabel | Literal[False] | None = ...,
usecols: list[HashableT]
| tuple[HashableT]
| Callable[[Hashable], bool]
| None = ...,
usecols: UsecolsArgType = ...,
dtype: DtypeArg | None = ...,
engine: CSVEngine | None = ...,
converters: Mapping[Hashable, Callable] | None = ...,
Expand Down Expand Up @@ -770,10 +764,7 @@ def read_csv(
header: int | Sequence[int] | None | Literal["infer"] = ...,
names: Sequence[Hashable] | None | lib.NoDefault = ...,
index_col: IndexLabel | Literal[False] | None = ...,
usecols: list[HashableT]
| tuple[HashableT]
| Callable[[Hashable], bool]
| None = ...,
usecols: UsecolsArgType = ...,
dtype: DtypeArg | None = ...,
engine: CSVEngine | None = ...,
converters: Mapping[Hashable, Callable] | None = ...,
Expand Down Expand Up @@ -833,10 +824,7 @@ def read_csv(
header: int | Sequence[int] | None | Literal["infer"] = ...,
names: Sequence[Hashable] | None | lib.NoDefault = ...,
index_col: IndexLabel | Literal[False] | None = ...,
usecols: list[HashableT]
| tuple[HashableT]
| Callable[[Hashable], bool]
| None = ...,
usecols: UsecolsArgType = ...,
dtype: DtypeArg | None = ...,
engine: CSVEngine | None = ...,
converters: Mapping[Hashable, Callable] | None = ...,
Expand Down Expand Up @@ -907,10 +895,7 @@ def read_csv(
header: int | Sequence[int] | None | Literal["infer"] = "infer",
names: Sequence[Hashable] | None | lib.NoDefault = lib.no_default,
index_col: IndexLabel | Literal[False] | None = None,
usecols: list[HashableT]
| tuple[HashableT]
| Callable[[Hashable], bool]
| None = None,
usecols: UsecolsArgType = None,
# General Parsing Configuration
dtype: DtypeArg | None = None,
engine: CSVEngine | None = None,
Expand Down Expand Up @@ -1005,10 +990,7 @@ def read_table(
header: int | Sequence[int] | None | Literal["infer"] = ...,
names: Sequence[Hashable] | None | lib.NoDefault = ...,
index_col: IndexLabel | Literal[False] | None = ...,
usecols: list[HashableT]
| tuple[HashableT]
| Callable[[Hashable], bool]
| None = ...,
usecols: UsecolsArgType = ...,
dtype: DtypeArg | None = ...,
engine: CSVEngine | None = ...,
converters: Mapping[Hashable, Callable] | None = ...,
Expand Down Expand Up @@ -1065,10 +1047,7 @@ def read_table(
header: int | Sequence[int] | None | Literal["infer"] = ...,
names: Sequence[Hashable] | None | lib.NoDefault = ...,
index_col: IndexLabel | Literal[False] | None = ...,
usecols: list[HashableT]
| tuple[HashableT]
| Callable[[Hashable], bool]
| None = ...,
usecols: UsecolsArgType = ...,
dtype: DtypeArg | None = ...,
engine: CSVEngine | None = ...,
converters: Mapping[Hashable, Callable] | None = ...,
Expand Down Expand Up @@ -1125,10 +1104,7 @@ def read_table(
header: int | Sequence[int] | None | Literal["infer"] = ...,
names: Sequence[Hashable] | None | lib.NoDefault = ...,
index_col: IndexLabel | Literal[False] | None = ...,
usecols: list[HashableT]
| tuple[HashableT]
| Callable[[Hashable], bool]
| None = ...,
usecols: UsecolsArgType = ...,
dtype: DtypeArg | None = ...,
engine: CSVEngine | None = ...,
converters: Mapping[Hashable, Callable] | None = ...,
Expand Down Expand Up @@ -1185,10 +1161,7 @@ def read_table(
header: int | Sequence[int] | None | Literal["infer"] = ...,
names: Sequence[Hashable] | None | lib.NoDefault = ...,
index_col: IndexLabel | Literal[False] | None = ...,
usecols: list[HashableT]
| tuple[HashableT]
| Callable[[Hashable], bool]
| None = ...,
usecols: UsecolsArgType = ...,
dtype: DtypeArg | None = ...,
engine: CSVEngine | None = ...,
converters: Mapping[Hashable, Callable] | None = ...,
Expand Down Expand Up @@ -1258,10 +1231,7 @@ def read_table(
header: int | Sequence[int] | None | Literal["infer"] = "infer",
names: Sequence[Hashable] | None | lib.NoDefault = lib.no_default,
index_col: IndexLabel | Literal[False] | None = None,
usecols: list[HashableT]
| tuple[HashableT]
| Callable[[Hashable], bool]
| None = None,
usecols: UsecolsArgType = None,
# General Parsing Configuration
dtype: DtypeArg | None = None,
engine: CSVEngine | None = None,
Expand Down
Loading