Skip to content

Commit

Permalink
TYP: read_csv's usecols (pandas-dev#55330)
Browse files Browse the repository at this point in the history
* TYP: read_csv's usecols

* adjust doc

* use range
  • Loading branch information
twoertwein authored Oct 4, 2023
1 parent 6a83910 commit da01e38
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 42 deletions.
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

0 comments on commit da01e38

Please sign in to comment.