diff --git a/pandas/io/parsers/base_parser.py b/pandas/io/parsers/base_parser.py index 7294efe843cce..dd03956a9a60e 100644 --- a/pandas/io/parsers/base_parser.py +++ b/pandas/io/parsers/base_parser.py @@ -112,8 +112,7 @@ def __init__(self, kwds) -> None: parse_dates = bool(parse_dates) elif not isinstance(parse_dates, list): raise TypeError( - "Only booleans and lists are accepted " - "for the 'parse_dates' parameter" + "Only booleans and lists are accepted for the 'parse_dates' parameter" ) self.parse_dates: bool | list = parse_dates self.date_parser = kwds.pop("date_parser", lib.no_default) @@ -244,7 +243,7 @@ def extract(r): names.insert(single_ic, single_ic) # Clean the column names (if we have an index_col). - if len(ic): + if ic: col_names = [ r[ic[0]] if ((r[ic[0]] is not None) and r[ic[0]] not in self.unnamed_cols) @@ -368,7 +367,7 @@ def _agg_index(self, index) -> Index: index_converter = converters.get(self.index_names[i]) is not None try_num_bool = not ( - cast_type and is_string_dtype(cast_type) or index_converter + (cast_type and is_string_dtype(cast_type)) or index_converter ) arr, _ = self._infer_types( @@ -716,7 +715,7 @@ def _get_empty_meta( # if dtype == None, default will be object. dtype_dict = defaultdict(lambda: dtype) else: - dtype = cast(dict, dtype) + dtype = cast("dict", dtype) dtype_dict = defaultdict( lambda: None, {columns[k] if is_integer(k) else k: v for k, v in dtype.items()}, @@ -895,15 +894,16 @@ def validate_parse_dates_presence( if not isinstance(parse_dates, list): return set() + columns_set = set(columns) missing = set() unique_cols = set() for col in parse_dates: if isinstance(col, str): - if col not in columns: + if col not in columns_set: missing.add(col) else: unique_cols.add(col) - elif col in columns: + elif col in columns_set: unique_cols.add(col) else: unique_cols.add(columns[col])