Skip to content

TYP: read_csv/table (names index_col) #47124

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 3 commits into from
Jun 3, 2022
Merged
Changes from 2 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
67 changes: 34 additions & 33 deletions pandas/io/parsers/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
IO,
Any,
Callable,
Hashable,
Literal,
NamedTuple,
Sequence,
Expand All @@ -23,11 +24,11 @@
import pandas._libs.lib as lib
from pandas._libs.parsers import STR_NA_VALUES
from pandas._typing import (
ArrayLike,
CompressionOptions,
CSVEngine,
DtypeArg,
FilePath,
IndexLabel,
ReadCsvBuffer,
StorageOptions,
)
Expand Down Expand Up @@ -521,7 +522,7 @@ def validate_integer(name, val, min_val=0):
return val


def _validate_names(names):
def _validate_names(names: Sequence[Hashable] | None) -> None:
"""
Raise ValueError if the `names` parameter contains duplicates or has an
invalid data type.
Expand Down Expand Up @@ -596,9 +597,9 @@ def read_csv(
sep: str | None | lib.NoDefault = ...,
delimiter: str | None | lib.NoDefault = ...,
header: int | Sequence[int] | None | Literal["infer"] = ...,
names=...,
index_col=...,
usecols=...,
names: Sequence[Hashable] | None | lib.NoDefault = ...,
index_col: IndexLabel | Literal[False] | None = ...,
usecols: Sequence[Hashable] | Callable[[Hashable], bool] | None = ...,
squeeze: bool | None = ...,
prefix: str | lib.NoDefault = ...,
mangle_dupe_cols: bool = ...,
Expand Down Expand Up @@ -656,9 +657,9 @@ def read_csv(
sep: str | None | lib.NoDefault = ...,
delimiter: str | None | lib.NoDefault = ...,
header: int | Sequence[int] | None | Literal["infer"] = ...,
names=...,
index_col=...,
usecols=...,
names: Sequence[Hashable] | None | lib.NoDefault = ...,
index_col: IndexLabel | Literal[False] | None = ...,
usecols: Sequence[Hashable] | Callable[[Hashable], bool] | None = ...,
squeeze: bool | None = ...,
prefix: str | lib.NoDefault = ...,
mangle_dupe_cols: bool = ...,
Expand Down Expand Up @@ -716,9 +717,9 @@ def read_csv(
sep: str | None | lib.NoDefault = ...,
delimiter: str | None | lib.NoDefault = ...,
header: int | Sequence[int] | None | Literal["infer"] = ...,
names=...,
index_col=...,
usecols=...,
names: Sequence[Hashable] | None | lib.NoDefault = ...,
index_col: IndexLabel | Literal[False] | None = ...,
usecols: Sequence[Hashable] | Callable[[Hashable], bool] | None = ...,
squeeze: bool | None = ...,
prefix: str | lib.NoDefault = ...,
mangle_dupe_cols: bool = ...,
Expand Down Expand Up @@ -776,9 +777,9 @@ def read_csv(
sep: str | None | lib.NoDefault = ...,
delimiter: str | None | lib.NoDefault = ...,
header: int | Sequence[int] | None | Literal["infer"] = ...,
names=...,
index_col=...,
usecols=...,
names: Sequence[Hashable] | None | lib.NoDefault = ...,
index_col: IndexLabel | Literal[False] | None = ...,
usecols: Sequence[Hashable] | Callable[[Hashable], bool] | None = ...,
squeeze: bool | None = ...,
prefix: str | lib.NoDefault = ...,
mangle_dupe_cols: bool = ...,
Expand Down Expand Up @@ -846,9 +847,9 @@ def read_csv(
delimiter: str | None | lib.NoDefault = None,
# Column and Index Locations and Names
header: int | Sequence[int] | None | Literal["infer"] = "infer",
names=lib.no_default,
index_col=None,
usecols=None,
names: Sequence[Hashable] | None | lib.NoDefault = lib.no_default,
index_col: IndexLabel | Literal[False] | None = None,
usecols: Sequence[Hashable] | Callable[[Hashable], bool] | None = None,
squeeze: bool | None = None,
prefix: str | lib.NoDefault = lib.no_default,
mangle_dupe_cols: bool = True,
Expand Down Expand Up @@ -935,9 +936,9 @@ def read_table(
sep: str | None | lib.NoDefault = ...,
delimiter: str | None | lib.NoDefault = ...,
header: int | Sequence[int] | None | Literal["infer"] = ...,
names=...,
index_col=...,
usecols=...,
names: Sequence[Hashable] | None | lib.NoDefault = ...,
index_col: IndexLabel | Literal[False] | None = ...,
usecols: Sequence[Hashable] | Callable[[Hashable], bool] | None = ...,
squeeze: bool | None = ...,
prefix: str | lib.NoDefault = ...,
mangle_dupe_cols: bool = ...,
Expand Down Expand Up @@ -995,9 +996,9 @@ def read_table(
sep: str | None | lib.NoDefault = ...,
delimiter: str | None | lib.NoDefault = ...,
header: int | Sequence[int] | None | Literal["infer"] = ...,
names=...,
index_col=...,
usecols=...,
names: Sequence[Hashable] | None | lib.NoDefault = ...,
index_col: IndexLabel | Literal[False] | None = ...,
usecols: Sequence[Hashable] | Callable[[Hashable], bool] | None = ...,
squeeze: bool | None = ...,
prefix: str | lib.NoDefault = ...,
mangle_dupe_cols: bool = ...,
Expand Down Expand Up @@ -1055,9 +1056,9 @@ def read_table(
sep: str | None | lib.NoDefault = ...,
delimiter: str | None | lib.NoDefault = ...,
header: int | Sequence[int] | None | Literal["infer"] = ...,
names=...,
index_col=...,
usecols=...,
names: Sequence[Hashable] | None | lib.NoDefault = ...,
index_col: IndexLabel | Literal[False] | None = ...,
usecols: Sequence[Hashable] | Callable[[Hashable], bool] | None = ...,
squeeze: bool | None = ...,
prefix: str | lib.NoDefault = ...,
mangle_dupe_cols: bool = ...,
Expand Down Expand Up @@ -1115,9 +1116,9 @@ def read_table(
sep: str | None | lib.NoDefault = ...,
delimiter: str | None | lib.NoDefault = ...,
header: int | Sequence[int] | None | Literal["infer"] = ...,
names=...,
index_col=...,
usecols=...,
names: Sequence[Hashable] | None | lib.NoDefault = ...,
index_col: IndexLabel | Literal[False] | None = ...,
usecols: Sequence[Hashable] | Callable[[Hashable], bool] | None = ...,
squeeze: bool | None = ...,
prefix: str | lib.NoDefault = ...,
mangle_dupe_cols: bool = ...,
Expand Down Expand Up @@ -1185,9 +1186,9 @@ def read_table(
delimiter: str | None | lib.NoDefault = None,
# Column and Index Locations and Names
header: int | Sequence[int] | None | Literal["infer"] = "infer",
names=lib.no_default,
index_col=None,
usecols=None,
names: Sequence[Hashable] | None | lib.NoDefault = lib.no_default,
index_col: IndexLabel | Literal[False] | None = None,
usecols: Sequence[Hashable] | Callable[[Hashable], bool] | None = None,
squeeze: bool | None = None,
prefix: str | lib.NoDefault = lib.no_default,
mangle_dupe_cols: bool = True,
Expand Down Expand Up @@ -1932,7 +1933,7 @@ def _refine_defaults_read(
error_bad_lines: bool | None,
warn_bad_lines: bool | None,
on_bad_lines: str | Callable | None,
names: ArrayLike | None | lib.NoDefault,
names: Sequence[Hashable] | None | lib.NoDefault,
prefix: str | None | lib.NoDefault,
defaults: dict[str, Any],
):
Expand Down