Skip to content

Commit 9567a31

Browse files
committed
Update readers.py
1 parent dba41de commit 9567a31

File tree

1 file changed

+43
-19
lines changed

1 file changed

+43
-19
lines changed

pandas/io/parsers/readers.py

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ class _read_shared(TypedDict, Generic[HashableT], total=False):
112112
skipfooter: int
113113
nrows: int | None
114114
na_values: (
115-
Hashable | Iterable[Hashable] | Mapping[Hashable, Iterable[Hashable]] | None
115+
Hashable | Iterable[Hashable] | Mapping[Hashable,
116+
Iterable[Hashable]] | None
116117
)
117118
keep_default_na: bool
118119
na_filter: bool
@@ -577,7 +578,10 @@ class _Fwf_Defaults(TypedDict):
577578
widths: None
578579

579580

580-
_fwf_defaults: _Fwf_Defaults = {"colspecs": "infer", "infer_nrows": 100, "widths": None}
581+
_fwf_defaults: _Fwf_Defaults = {
582+
"colspecs": "infer",
583+
"infer_nrows": 100,
584+
"widths": None}
581585
_c_unsupported = {"skipfooter"}
582586
_python_unsupported = {"low_memory", "float_precision"}
583587
_pyarrow_unsupported = {
@@ -608,7 +612,10 @@ def validate_integer(name: str, val: float, min_val: int = ...) -> int: ...
608612

609613

610614
@overload
611-
def validate_integer(name: str, val: int | None, min_val: int = ...) -> int | None: ...
615+
def validate_integer(
616+
name: str,
617+
val: int | None,
618+
min_val: int = ...) -> int | None: ...
612619

613620

614621
def validate_integer(
@@ -662,7 +669,9 @@ def _validate_names(names: Sequence[Hashable] | None) -> None:
662669
if len(names) != len(set(names)):
663670
raise ValueError("Duplicate names are not allowed.")
664671
if not (
665-
is_list_like(names, allow_sets=False) or isinstance(names, abc.KeysView)
672+
is_list_like(
673+
names, allow_sets=False) or isinstance(
674+
names, abc.KeysView)
666675
):
667676
raise ValueError("Names should be an ordered collection.")
668677

@@ -781,7 +790,8 @@ def read_csv(
781790
nrows: int | None = None,
782791
# NA and Missing Data Handling
783792
na_values: (
784-
Hashable | Iterable[Hashable] | Mapping[Hashable, Iterable[Hashable]] | None
793+
Hashable | Iterable[Hashable] | Mapping[Hashable,
794+
Iterable[Hashable]] | None
785795
) = None,
786796
keep_default_na: bool = True,
787797
na_filter: bool = True,
@@ -1360,7 +1370,8 @@ def read_table(
13601370
nrows: int | None = None,
13611371
# NA and Missing Data Handling
13621372
na_values: (
1363-
Hashable | Iterable[Hashable] | Mapping[Hashable, Iterable[Hashable]] | None
1373+
Hashable | Iterable[Hashable] | Mapping[Hashable,
1374+
Iterable[Hashable]] | None
13641375
) = None,
13651376
keep_default_na: bool = True,
13661377
na_filter: bool = True,
@@ -1974,7 +1985,8 @@ def read_fwf(
19741985
if colspecs is None and widths is None:
19751986
raise ValueError("Must specify either colspecs or widths")
19761987
if colspecs not in (None, "infer") and widths is not None:
1977-
raise ValueError("You must specify only one of 'widths' and 'colspecs'")
1988+
raise ValueError(
1989+
"You must specify only one of 'widths' and 'colspecs'")
19781990

19791991
# Compute 'colspecs' from 'widths', if specified.
19801992
if widths is not None:
@@ -2004,9 +2016,11 @@ def read_fwf(
20042016
assert index_col is not lib.no_default
20052017

20062018
len_index = len(index_col)
2007-
if kwds.get("usecols") is None and len(names) + len_index != len(colspecs):
2019+
if kwds.get("usecols") is None and len(
2020+
names) + len_index != len(colspecs):
20082021
# If usecols is used colspec may be longer than names
2009-
raise ValueError("Length of colspecs must match length of names")
2022+
raise ValueError(
2023+
"Length of colspecs must match length of names")
20102024

20112025
check_dtype_backend(kwds.setdefault("dtype_backend", lib.no_default))
20122026
return _read(
@@ -2098,7 +2112,8 @@ def _get_options_with_defaults(self, engine: CSVEngine) -> dict[str, Any]:
20982112
and value != getattr(value, "value", default)
20992113
):
21002114
raise ValueError(
2101-
f"The {argname!r} option is not supported with the 'pyarrow' engine"
2115+
f"The {
2116+
argname!r} option is not supported with the 'pyarrow' engine"
21022117
)
21032118
options[argname] = value
21042119

@@ -2114,7 +2129,8 @@ def _get_options_with_defaults(self, engine: CSVEngine) -> dict[str, Any]:
21142129
pass
21152130
else:
21162131
raise ValueError(
2117-
f"The {argname!r} option is not supported with the "
2132+
f"The {
2133+
argname!r} option is not supported with the "
21182134
f"{engine!r} engine"
21192135
)
21202136
else:
@@ -2215,7 +2231,8 @@ def _clean_options(
22152231

22162232
if "python" in engine:
22172233
for arg in _python_unsupported:
2218-
if fallback_reason and result[arg] != _c_parser_defaults.get(arg):
2234+
if fallback_reason and result[arg] != _c_parser_defaults.get(
2235+
arg):
22192236
raise ValueError(
22202237
"Falling back to the 'python' engine because "
22212238
f"{fallback_reason}, but this causes {arg!r} to be "
@@ -2314,7 +2331,8 @@ def _make_engine(
23142331

23152332
if engine not in mapping:
23162333
raise ValueError(
2317-
f"Unknown engine: {engine} (valid options are {mapping.keys()})"
2334+
f"Unknown engine: {engine} (valid options are {
2335+
mapping.keys()})"
23182336
)
23192337
if not isinstance(f, list):
23202338
# open file here
@@ -2399,7 +2417,8 @@ def read(self, nrows: int | None = None) -> DataFrame:
23992417
dtype_arg = None
24002418

24012419
if isinstance(dtype_arg, dict):
2402-
dtype = defaultdict(lambda: None) # type: ignore[var-annotated]
2420+
# type: ignore[var-annotated]
2421+
dtype = defaultdict(lambda: None)
24032422
dtype.update(dtype_arg)
24042423
elif dtype_arg is not None and pandas_dtype(dtype_arg) in (
24052424
np.str_,
@@ -2417,7 +2436,8 @@ def read(self, nrows: int | None = None) -> DataFrame:
24172436
if pandas_dtype(dtype[k]) in (np.str_, np.object_)
24182437
else None
24192438
)
2420-
new_col_dict[k] = Series(v, index=index, dtype=d, copy=False)
2439+
new_col_dict[k] = Series(
2440+
v, index=index, dtype=d, copy=False)
24212441
else:
24222442
new_col_dict = col_dict
24232443

@@ -2508,7 +2528,8 @@ def TextParser(*args, **kwds) -> TextFileReader:
25082528
return TextFileReader(*args, **kwds)
25092529

25102530

2511-
def _clean_na_values(na_values, keep_default_na: bool = True, floatify: bool = True):
2531+
def _clean_na_values(na_values, keep_default_na: bool = True,
2532+
floatify: bool = True):
25122533
na_fvalues: set | dict
25132534
if na_values is None:
25142535
if keep_default_na:
@@ -2648,7 +2669,8 @@ def _refine_defaults_read(
26482669
)
26492670

26502671
if delimiter and (sep is not lib.no_default):
2651-
raise ValueError("Specified a sep and a delimiter; you can only specify one.")
2672+
raise ValueError(
2673+
"Specified a sep and a delimiter; you can only specify one.")
26522674

26532675
kwds["names"] = None if names is lib.no_default else names
26542676

@@ -2689,7 +2711,8 @@ def _refine_defaults_read(
26892711
)
26902712
kwds["on_bad_lines"] = on_bad_lines
26912713
else:
2692-
raise ValueError(f"Argument {on_bad_lines} is invalid for on_bad_lines")
2714+
raise ValueError(
2715+
f"Argument {on_bad_lines} is invalid for on_bad_lines")
26932716

26942717
check_dtype_backend(dtype_backend)
26952718

@@ -2711,7 +2734,8 @@ def _extract_dialect(kwds: dict[str, str | csv.Dialect]) -> csv.Dialect | None:
27112734

27122735
dialect = kwds["dialect"]
27132736
if isinstance(dialect, str) and dialect in csv.list_dialects():
2714-
# get_dialect is typed to return a `_csv.Dialect` for some reason in typeshed
2737+
# get_dialect is typed to return a `_csv.Dialect` for some reason in
2738+
# typeshed
27152739
tdialect = cast(csv.Dialect, csv.get_dialect(dialect))
27162740
_validate_dialect(tdialect)
27172741

0 commit comments

Comments
 (0)