From 9a1c4524f2dd4eaf7a164cced0eff2832e0210e8 Mon Sep 17 00:00:00 2001 From: Lirong Date: Thu, 25 Sep 2025 01:06:28 +0000 Subject: [PATCH 1/9] strict to true for info --- pandas/io/formats/info.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/pandas/io/formats/info.py b/pandas/io/formats/info.py index eb579f7149d44..47792c6e6a8e0 100644 --- a/pandas/io/formats/info.py +++ b/pandas/io/formats/info.py @@ -868,12 +868,14 @@ def _get_gross_column_widths(self) -> Sequence[int]: body_column_widths = self._get_body_column_widths() return [ max(*widths) - for widths in zip(self.header_column_widths, body_column_widths) + for widths in zip( + self.header_column_widths, body_column_widths, strict=True + ) ] def _get_body_column_widths(self) -> Sequence[int]: """Get widths of table content columns.""" - strcols: Sequence[Sequence[str]] = list(zip(*self.strrows)) + strcols: Sequence[Sequence[str]] = list(zip(*self.strrows, strict=True)) return [max(len(x) for x in col) for col in strcols] def _gen_rows(self) -> Iterator[Sequence[str]]: @@ -899,7 +901,9 @@ def add_header_line(self) -> None: header_line = self.SPACING.join( [ _put_str(header, col_width) - for header, col_width in zip(self.headers, self.gross_column_widths) + for header, col_width in zip( + self.headers, self.gross_column_widths, strict=True + ) ] ) self._lines.append(header_line) @@ -920,7 +924,9 @@ def add_body_lines(self) -> None: body_line = self.SPACING.join( [ _put_str(col, gross_colwidth) - for col, gross_colwidth in zip(row, self.gross_column_widths) + for col, gross_colwidth in zip( + row, self.gross_column_widths, strict=True + ) ] ) self._lines.append(body_line) @@ -980,6 +986,7 @@ def _gen_rows_without_counts(self) -> Iterator[Sequence[str]]: self._gen_line_numbers(), self._gen_columns(), self._gen_dtypes(), + strict=True, ) def _gen_rows_with_counts(self) -> Iterator[Sequence[str]]: @@ -989,6 +996,7 @@ def _gen_rows_with_counts(self) -> Iterator[Sequence[str]]: self._gen_columns(), self._gen_non_null_counts(), self._gen_dtypes(), + strict=True, ) def _gen_line_numbers(self) -> Iterator[str]: @@ -1092,10 +1100,7 @@ def _gen_rows_without_counts(self) -> Iterator[Sequence[str]]: def _gen_rows_with_counts(self) -> Iterator[Sequence[str]]: """Iterator with string representation of body data with counts.""" - yield from zip( - self._gen_non_null_counts(), - self._gen_dtypes(), - ) + yield from zip(self._gen_non_null_counts(), self._gen_dtypes(), strict=True) def _get_dataframe_dtype_counts(df: DataFrame) -> Mapping[str, int]: From ccdc4f5ddf6824716c726e2755ce8fa48b4c9c4c Mon Sep 17 00:00:00 2001 From: Lirong Date: Fri, 26 Sep 2025 20:44:16 +0000 Subject: [PATCH 2/9] add strict to true for zip --- pandas/io/excel/_xlrd.py | 4 +++- pandas/io/formats/css.py | 2 +- pandas/io/formats/excel.py | 9 ++++++--- pandas/io/formats/format.py | 13 ++++++++----- pandas/io/formats/html.py | 13 +++++++++---- pandas/io/formats/info.py | 2 +- pandas/io/formats/printing.py | 10 ++++++---- pandas/io/formats/style_render.py | 4 ++-- pandas/io/json/_normalize.py | 4 ++-- pandas/io/json/_table_schema.py | 2 +- pandas/io/parsers/base_parser.py | 4 ++-- pandas/io/parsers/c_parser_wrapper.py | 4 ++-- pandas/io/parsers/python_parser.py | 4 ++-- pandas/io/pytables.py | 16 ++++++++++------ pandas/io/sas/sas_xport.py | 2 +- pandas/io/sql.py | 8 +++++--- pandas/io/stata.py | 10 +++++----- pandas/io/xml.py | 12 +++++++----- 18 files changed, 73 insertions(+), 50 deletions(-) diff --git a/pandas/io/excel/_xlrd.py b/pandas/io/excel/_xlrd.py index 5d39a840336eb..46b0064247096 100644 --- a/pandas/io/excel/_xlrd.py +++ b/pandas/io/excel/_xlrd.py @@ -134,7 +134,9 @@ def _parse_cell(cell_contents, cell_typ): return [ [ _parse_cell(value, typ) - for value, typ in zip(sheet.row_values(i), sheet.row_types(i)) + for value, typ in zip( + sheet.row_values(i), sheet.row_types(i), strict=True + ) ] for i in range(nrows) ] diff --git a/pandas/io/formats/css.py b/pandas/io/formats/css.py index 10c970887e03b..0f1a7302aa808 100644 --- a/pandas/io/formats/css.py +++ b/pandas/io/formats/css.py @@ -57,7 +57,7 @@ def expand(self: CSSResolver, prop: str, value: str) -> Generator[tuple[str, str stacklevel=find_stack_level(), ) return - for key, idx in zip(self.SIDES, mapping): + for key, idx in zip(self.SIDES, mapping, strict=True): yield prop_fmt.format(key), tokens[idx] return expand diff --git a/pandas/io/formats/excel.py b/pandas/io/formats/excel.py index f2cf1a4838c36..a5a3f62300575 100644 --- a/pandas/io/formats/excel.py +++ b/pandas/io/formats/excel.py @@ -633,7 +633,7 @@ def _format_header_mi(self) -> Iterable[ExcelCell]: ) for lnum, (spans, levels, level_codes) in enumerate( - zip(level_lengths, columns.levels, columns.codes) + zip(level_lengths, columns.levels, columns.codes, strict=True) ): values = levels.take(level_codes) for i, span_val in spans.items(): @@ -792,7 +792,10 @@ def _format_hierarchical_rows(self) -> Iterable[ExcelCell]: level_lengths = get_level_lengths(level_strs) for spans, levels, level_codes in zip( - level_lengths, self.df.index.levels, self.df.index.codes + level_lengths, + self.df.index.levels, + self.df.index.codes, + strict=True, ): values = levels.take( level_codes, @@ -824,7 +827,7 @@ def _format_hierarchical_rows(self) -> Iterable[ExcelCell]: else: # Format hierarchical rows with non-merged values. - for indexcolvals in zip(*self.df.index): + for indexcolvals in zip(*self.df.index, strict=True): for idx, indexcolval in enumerate(indexcolvals): # GH#60099 if isinstance(indexcolval, Period): diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index 7e0900f64b6bf..b0011fc1cf595 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -579,7 +579,7 @@ def _initialize_colspace(self, col_space: ColspaceArgType | None) -> ColspaceTyp f"Col_space length({len(col_space)}) should match " f"DataFrame number of columns({len(self.frame.columns)})" ) - result = dict(zip(self.frame.columns, col_space)) + result = dict(zip(self.frame.columns, col_space, strict=True)) return result def _calc_max_cols_fitted(self) -> int | None: @@ -786,7 +786,7 @@ def _get_formatted_column_labels(self, frame: DataFrame) -> list[list[str]]: if self.sparsify and len(fmt_columns): fmt_columns = sparsify_labels(fmt_columns) - str_columns = [list(x) for x in zip(*fmt_columns)] + str_columns = [list(x) for x in zip(*fmt_columns, strict=True)] else: fmt_columns = columns._format_flat(include_name=False) str_columns = [ @@ -795,7 +795,9 @@ def _get_formatted_column_labels(self, frame: DataFrame) -> list[list[str]]: if not self._get_formatter(i) and is_numeric_dtype(dtype) else x ] - for i, (x, dtype) in enumerate(zip(fmt_columns, self.frame.dtypes)) + for i, (x, dtype) in enumerate( + zip(fmt_columns, self.frame.dtypes, strict=True) + ) ] return str_columns @@ -1359,7 +1361,7 @@ def format_with_na_rep( formatted = np.array( [ formatter(val) if not m else na_rep - for val, m in zip(values.ravel(), mask.ravel()) + for val, m in zip(values.ravel(), mask.ravel(), strict=True) ] ).reshape(values.shape) return formatted @@ -1377,6 +1379,7 @@ def format_complex_with_na_rep( imag_values, real_mask, imag_mask, + strict=True, ): if not re_isna and not im_isna: formatted_lst.append(formatter(val)) @@ -1796,7 +1799,7 @@ def _trim_zeros_complex(str_complexes: ArrayLike, decimal: str = ".") -> list[st + imag_pt[0] # +/- + f"{imag_pt[1:]:>{padded_length}}" # complex part (no sign), possibly nan + "j" - for real_pt, imag_pt in zip(padded_parts[:n], padded_parts[n:]) + for real_pt, imag_pt in zip(padded_parts[:n], padded_parts[n:], strict=True) ] return padded diff --git a/pandas/io/formats/html.py b/pandas/io/formats/html.py index c4884ef4ce4a9..2046a8269581e 100644 --- a/pandas/io/formats/html.py +++ b/pandas/io/formats/html.py @@ -289,7 +289,9 @@ def _write_col_header(self, indent: int) -> None: levels = self.columns._format_multi(sparsify=sentinel, include_names=False) level_lengths = get_level_lengths(levels, sentinel) inner_lvl = len(level_lengths) - 1 - for lnum, (records, values) in enumerate(zip(level_lengths, levels)): + for lnum, (records, values) in enumerate( + zip(level_lengths, levels, strict=True) + ): if is_truncated_horizontally: # modify the header lines ins_col = self.fmt.tr_col_num @@ -486,7 +488,7 @@ def _write_hierarchical_rows( assert isinstance(frame.index, MultiIndex) idx_values = frame.index._format_multi(sparsify=False, include_names=False) - idx_values = list(zip(*idx_values)) + idx_values = list(zip(*idx_values, strict=True)) if self.fmt.sparsify: # GH3547 @@ -547,7 +549,7 @@ def _write_hierarchical_rows( sparse_offset = 0 j = 0 - for records, v in zip(level_lengths, idx_values[i]): + for records, v in zip(level_lengths, idx_values[i], strict=True): if i in records: if records[i] > 1: tags[j] = template.format(span=records[i]) @@ -584,7 +586,10 @@ def _write_hierarchical_rows( ) idx_values = list( - zip(*frame.index._format_multi(sparsify=False, include_names=False)) + zip( + *frame.index._format_multi(sparsify=False, include_names=False), + strict=True, + ) ) row = [] row.extend(idx_values[i]) diff --git a/pandas/io/formats/info.py b/pandas/io/formats/info.py index 47792c6e6a8e0..441ffec7f2b73 100644 --- a/pandas/io/formats/info.py +++ b/pandas/io/formats/info.py @@ -913,7 +913,7 @@ def add_separator_line(self) -> None: [ _put_str("-" * header_colwidth, gross_colwidth) for header_colwidth, gross_colwidth in zip( - self.header_column_widths, self.gross_column_widths + self.header_column_widths, self.gross_column_widths, strict=True ) ] ) diff --git a/pandas/io/formats/printing.py b/pandas/io/formats/printing.py index 9de5ac071495b..8f4d7302453c2 100644 --- a/pandas/io/formats/printing.py +++ b/pandas/io/formats/printing.py @@ -60,7 +60,7 @@ def adjoin(space: int, *lists: list[str], **kwargs: Any) -> str: nl = justfunc(lst, lengths[i], mode="left") nl = ([" " * lengths[i]] * (maxLen - len(lst))) + nl newLists.append(nl) - toJoin = zip(*newLists) + toJoin = zip(*newLists, strict=True) return "\n".join("".join(lines) for lines in toJoin) @@ -497,14 +497,16 @@ def _justify( max_length = [0] * len(combined[0]) for inner_seq in combined: length = [len(item) for item in inner_seq] - max_length = [max(x, y) for x, y in zip(max_length, length)] + max_length = [max(x, y) for x, y in zip(max_length, length, strict=True)] # justify each item in each list-like in head and tail using max_length head_tuples = [ - tuple(x.rjust(max_len) for x, max_len in zip(seq, max_length)) for seq in head + tuple(x.rjust(max_len) for x, max_len in zip(seq, max_length, strict=True)) + for seq in head ] tail_tuples = [ - tuple(x.rjust(max_len) for x, max_len in zip(seq, max_length)) for seq in tail + tuple(x.rjust(max_len) for x, max_len in zip(seq, max_length, strict=True)) + for seq in tail ] return head_tuples, tail_tuples diff --git a/pandas/io/formats/style_render.py b/pandas/io/formats/style_render.py index 11ef37a0d69f3..ba9b3aff01d7b 100644 --- a/pandas/io/formats/style_render.py +++ b/pandas/io/formats/style_render.py @@ -429,7 +429,7 @@ def _translate_header(self, sparsify_cols: bool, max_cols: int): clabels = self.data.columns.tolist() if self.data.columns.nlevels == 1: clabels = [[x] for x in clabels] - clabels = list(zip(*clabels)) + clabels = list(zip(*clabels, strict=True)) head = [] # 1) column headers @@ -914,7 +914,7 @@ def concatenated_visible_rows(obj): return row_indices body = [] - for r, row in zip(concatenated_visible_rows(self), d["body"]): + for r, row in zip(concatenated_visible_rows(self), d["body"], strict=True): # note: cannot enumerate d["body"] because rows were dropped if hidden # during _translate_body so must zip to acquire the true r-index associated # with the ctx obj which contains the cell styles. diff --git a/pandas/io/json/_normalize.py b/pandas/io/json/_normalize.py index 71a0c674eebac..680f4289fdbff 100644 --- a/pandas/io/json/_normalize.py +++ b/pandas/io/json/_normalize.py @@ -550,7 +550,7 @@ def _recursive_extract(data, path, seen_meta, level: int = 0) -> None: data = [data] if len(path) > 1: for obj in data: - for val, key in zip(_meta, meta_keys): + for val, key in zip(_meta, meta_keys, strict=True): if level + 1 == len(val): seen_meta[key] = _pull_field(obj, val[-1]) @@ -567,7 +567,7 @@ def _recursive_extract(data, path, seen_meta, level: int = 0) -> None: # For repeating the metadata later lengths.append(len(recs)) - for val, key in zip(_meta, meta_keys): + for val, key in zip(_meta, meta_keys, strict=True): if level + 1 > len(val): meta_val = seen_meta[key] else: diff --git a/pandas/io/json/_table_schema.py b/pandas/io/json/_table_schema.py index 5510036e542f5..1723be3de6e82 100644 --- a/pandas/io/json/_table_schema.py +++ b/pandas/io/json/_table_schema.py @@ -308,7 +308,7 @@ def build_table_schema( if index: if data.index.nlevels > 1: data.index = cast("MultiIndex", data.index) - for level, name in zip(data.index.levels, data.index.names): + for level, name in zip(data.index.levels, data.index.names, strict=True): new_field = convert_pandas_type_to_json_field(level) new_field["name"] = name fields.append(new_field) diff --git a/pandas/io/parsers/base_parser.py b/pandas/io/parsers/base_parser.py index 23efc9c87e07c..9b2d66625808b 100644 --- a/pandas/io/parsers/base_parser.py +++ b/pandas/io/parsers/base_parser.py @@ -237,7 +237,7 @@ def _extract_multi_indexer_columns( def extract(r): return tuple(r[i] for i in range(field_count) if i not in sic) - columns = list(zip(*(extract(r) for r in header))) + columns = list(zip(*(extract(r) for r in header), strict=True)) names = columns.copy() for single_ic in sorted(ic): names.insert(single_ic, single_ic) @@ -330,7 +330,7 @@ def _agg_index(self, index) -> Index: names: Iterable = self.index_names else: names = itertools.cycle([None]) - for i, (arr, name) in enumerate(zip(index, names)): + for i, (arr, name) in enumerate(zip(index, names, strict=True)): if self._should_parse_dates(i): arr = date_converter( arr, diff --git a/pandas/io/parsers/c_parser_wrapper.py b/pandas/io/parsers/c_parser_wrapper.py index 4304d27d74ea9..e3f02d44facaa 100644 --- a/pandas/io/parsers/c_parser_wrapper.py +++ b/pandas/io/parsers/c_parser_wrapper.py @@ -292,7 +292,7 @@ def read( # rename dict keys data_tups = sorted(data.items()) - data = {k: v for k, (i, v) in zip(names, data_tups)} + data = {k: v for k, (i, v) in zip(names, data_tups, strict=True)} date_data = self._do_date_conversions(names, data) @@ -317,7 +317,7 @@ def read( if self.usecols is None: self._check_data_length(names, alldata) - data = {k: v for k, (i, v) in zip(names, data_tups)} + data = {k: v for k, (i, v) in zip(names, data_tups, strict=True)} date_data = self._do_date_conversions(names, data) index, column_names = self._make_index(alldata, names) diff --git a/pandas/io/parsers/python_parser.py b/pandas/io/parsers/python_parser.py index 2b538f5e3cef4..e5cd8d13ec7d4 100644 --- a/pandas/io/parsers/python_parser.py +++ b/pandas/io/parsers/python_parser.py @@ -1341,7 +1341,7 @@ def _set_no_thousand_columns(self) -> set[int]: ) if self.columns and self.dtype: assert self._col_indices is not None - for i, col in zip(self._col_indices, self.columns): + for i, col in zip(self._col_indices, self.columns, strict=True): if not isinstance(self.dtype, dict) and not is_numeric_dtype( self.dtype ): @@ -1458,7 +1458,7 @@ def detect_colspecs( shifted = np.roll(mask, 1) shifted[0] = 0 edges = np.where((mask ^ shifted) == 1)[0] - edge_pairs = list(zip(edges[::2], edges[1::2])) + edge_pairs = list(zip(edges[::2], edges[1::2], strict=True)) return edge_pairs def __next__(self) -> list[str]: diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index 088cae8e20524..abd2ecf7b81d7 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -1074,7 +1074,7 @@ def select_as_multiple( # validate rows nrows = None - for t, k in itertools.chain([(s, selector)], zip(tbls, keys)): + for t, k in itertools.chain([(s, selector)], zip(tbls, keys, strict=True)): if t is None: raise KeyError(f"Invalid table [{k}]") if not t.is_table: @@ -2207,7 +2207,9 @@ def __repr__(self) -> str: return ",".join( [ f"{key}->{value}" - for key, value in zip(["name", "cname", "axis", "pos", "kind"], temp) + for key, value in zip( + ["name", "cname", "axis", "pos", "kind"], temp, strict=True + ) ] ) @@ -2532,7 +2534,9 @@ def __repr__(self) -> str: return ",".join( [ f"{key}->{value}" - for key, value in zip(["name", "cname", "dtype", "kind", "shape"], temp) + for key, value in zip( + ["name", "cname", "dtype", "kind", "shape"], temp, strict=True + ) ] ) @@ -3125,7 +3129,7 @@ def write_multi_index(self, key: str, index: MultiIndex) -> None: setattr(self.attrs, f"{key}_nlevels", index.nlevels) for i, (lev, level_codes, name) in enumerate( - zip(index.levels, index.codes, index.names) + zip(index.levels, index.codes, index.names, strict=True) ): # write the level if isinstance(lev.dtype, ExtensionDtype): @@ -4160,7 +4164,7 @@ def _create_axes( # add my values vaxes = [] - for i, (blk, b_items) in enumerate(zip(blocks, blk_items)): + for i, (blk, b_items) in enumerate(zip(blocks, blk_items, strict=True)): # shape of the data column are the indexable axes klass = DataCol name = None @@ -4301,7 +4305,7 @@ def get_blk_items(mgr): if table_exists: by_items = { tuple(b_items.tolist()): (b, b_items) - for b, b_items in zip(blocks, blk_items) + for b, b_items in zip(blocks, blk_items, strict=True) } new_blocks: list[Block] = [] new_blk_items = [] diff --git a/pandas/io/sas/sas_xport.py b/pandas/io/sas/sas_xport.py index a9c45e720fd56..fd967503305c3 100644 --- a/pandas/io/sas/sas_xport.py +++ b/pandas/io/sas/sas_xport.py @@ -359,7 +359,7 @@ def _read_header(self) -> None: fieldbytes = fieldbytes.ljust(140) fieldstruct = struct.unpack(">hhhh8s40s8shhh2s8shhl52s", fieldbytes) - field = dict(zip(_fieldkeys, fieldstruct)) + field = dict(zip(_fieldkeys, fieldstruct, strict=True)) del field["_"] field["ntype"] = types[field["ntype"]] fl = field["field_length"] diff --git a/pandas/io/sql.py b/pandas/io/sql.py index 18129257af1c9..81adeab0e1907 100644 --- a/pandas/io/sql.py +++ b/pandas/io/sql.py @@ -1006,7 +1006,7 @@ def _execute_insert(self, conn, keys: list[str], data_iter) -> int: data_iter : generator of list Each item contains a list of values to be inserted """ - data = [dict(zip(keys, row)) for row in data_iter] + data = [dict(zip(keys, row, strict=True)) for row in data_iter] result = self.pd_sql.execute(self.table.insert(), data) return result.rowcount @@ -1022,7 +1022,7 @@ def _execute_insert_multi(self, conn, keys: list[str], data_iter) -> int: from sqlalchemy import insert - data = [dict(zip(keys, row)) for row in data_iter] + data = [dict(zip(keys, row, strict=True)) for row in data_iter] stmt = insert(self.table).values(data) result = self.pd_sql.execute(stmt) return result.rowcount @@ -1112,7 +1112,9 @@ def insert( if start_i >= end_i: break - chunk_iter = zip(*(arr[start_i:end_i] for arr in data_list)) + chunk_iter = zip( + *(arr[start_i:end_i] for arr in data_list), strict=True + ) num_inserted = exec_insert(conn, keys, chunk_iter) # GH 46891 if num_inserted is not None: diff --git a/pandas/io/stata.py b/pandas/io/stata.py index 27e1bac7ac8e0..979f00973958b 100644 --- a/pandas/io/stata.py +++ b/pandas/io/stata.py @@ -1771,7 +1771,7 @@ def read( data = self._do_select_columns(data, columns) # Decode strings - for col, typ in zip(data, self._typlist): + for col, typ in zip(data, self._typlist, strict=True): if isinstance(typ, int): data[col] = data[col].apply(self._decode) @@ -1941,7 +1941,7 @@ def _do_convert_categoricals( if not value_label_dict: return data cat_converted_data = [] - for col, label in zip(data, lbllist): + for col, label in zip(data, lbllist, strict=True): if label in value_label_dict: # Explicit call with ordered=True vl = value_label_dict[label] @@ -2087,7 +2087,7 @@ def variable_labels(self) -> dict[str, str]: 1 1 3 4 """ self._ensure_open() - return dict(zip(self._varlist, self._variable_labels)) + return dict(zip(self._varlist, self._variable_labels, strict=True)) def value_labels(self) -> dict[str, dict[int, str]]: """ @@ -2490,7 +2490,7 @@ def _prepare_categoricals(self, data: DataFrame) -> DataFrame: get_base_missing_value = StataMissingValue.get_base_missing_value data_formatted = [] - for col, col_is_cat in zip(data, is_cat): + for col, col_is_cat in zip(data, is_cat, strict=True): if col_is_cat: svl = StataValueLabel(data[col], encoding=self._encoding) self._value_labels.append(svl) @@ -2619,7 +2619,7 @@ def _check_column_names(self, data: DataFrame) -> DataFrame: # Check date conversion, and fix key if needed if self._convert_dates: - for c, o in zip(columns, original_columns): + for c, o in zip(columns, original_columns, strict=True): if c != o: self._convert_dates[c] = self._convert_dates[o] del self._convert_dates[o] diff --git a/pandas/io/xml.py b/pandas/io/xml.py index e14f401d41f2a..2773d2b72a8ee 100644 --- a/pandas/io/xml.py +++ b/pandas/io/xml.py @@ -222,7 +222,7 @@ def _parse_nodes(self, elems: list[Any]) -> list[dict[str, str | None]]: ), **{ nm: ch.text if ch.text else None - for nm, ch in zip(self.names, el.findall("*")) + for nm, ch in zip(self.names, el.findall("*"), strict=True) }, } for el in elems @@ -245,7 +245,7 @@ def _parse_nodes(self, elems: list[Any]) -> list[dict[str, str | None]]: **({el.tag: el.text} if el.text and not el.text.isspace() else {}), **{ nm: ch.text if ch.text else None - for nm, ch in zip(self.names, el.findall("*")) + for nm, ch in zip(self.names, el.findall("*"), strict=True) }, } for el in elems @@ -269,7 +269,7 @@ def _parse_nodes(self, elems: list[Any]) -> list[dict[str, str | None]]: dicts = [{k: d[k] if k in d.keys() else None for k in keys} for d in dicts] if self.names: - dicts = [dict(zip(self.names, d.values())) for d in dicts] + dicts = [dict(zip(self.names, d.values(), strict=True)) for d in dicts] return dicts @@ -339,7 +339,9 @@ def _iterparse_nodes(self, iterparse: Callable) -> list[dict[str, str | None]]: if row is not None: if self.names and iterparse_repeats: - for col, nm in zip(self.iterparse[row_node], self.names): + for col, nm in zip( + self.iterparse[row_node], self.names, strict=True + ): if curr_elem == col: elem_val = elem.text if elem.text else None if elem_val not in row.values() and nm not in row: @@ -374,7 +376,7 @@ def _iterparse_nodes(self, iterparse: Callable) -> list[dict[str, str | None]]: dicts = [{k: d[k] if k in d.keys() else None for k in keys} for d in dicts] if self.names: - dicts = [dict(zip(self.names, d.values())) for d in dicts] + dicts = [dict(zip(self.names, d.values(), strict=True)) for d in dicts] return dicts From 8065ce1c35800ddd4063b4a0e44a2a6e62536d7b Mon Sep 17 00:00:00 2001 From: Lirong Date: Sun, 28 Sep 2025 19:08:50 +0000 Subject: [PATCH 3/9] remove io files from pyproject --- pyproject.toml | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 7c7cf0c2fc619..50b7203c438e0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -476,24 +476,6 @@ exclude = [ "pandas/core/sorting.py" = ["B905"] "pandas/core/strings/accessor.py" = ["B905"] "pandas/core/window/rolling.py" = ["B905"] -"pandas/io/excel/_xlrd.py" = ["B905"] -"pandas/io/formats/css.py" = ["B905"] -"pandas/io/formats/excel.py" = ["B905"] -"pandas/io/formats/format.py" = ["B905"] -"pandas/io/formats/html.py" = ["B905"] -"pandas/io/formats/info.py" = ["B905"] -"pandas/io/formats/printing.py" = ["B905"] -"pandas/io/formats/style_render.py" = ["B905"] -"pandas/io/json/_normalize.py" = ["B905"] -"pandas/io/json/_table_schema.py" = ["B905"] -"pandas/io/parsers/base_parser.py" = ["B905"] -"pandas/io/parsers/c_parser_wrapper.py" = ["B905"] -"pandas/io/parsers/python_parser.py" = ["B905"] -"pandas/io/pytables.py" = ["B905"] -"pandas/io/sas/sas_xport.py" = ["B905"] -"pandas/io/sql.py" = ["B905"] -"pandas/io/stata.py" = ["B905"] -"pandas/io/xml.py" = ["B905"] "pandas/plotting/_core.py" = ["B905"] "pandas/plotting/_matplotlib/boxplot.py" = ["B905"] "pandas/plotting/_matplotlib/core.py" = ["B905"] From e5a97508174427921e5454dba8b7b13460d72389 Mon Sep 17 00:00:00 2001 From: Lirong Date: Sun, 28 Sep 2025 19:29:13 +0000 Subject: [PATCH 4/9] set strict to false in format.py --- pandas/io/formats/format.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index b0011fc1cf595..7de26249762bb 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -796,7 +796,7 @@ def _get_formatted_column_labels(self, frame: DataFrame) -> list[list[str]]: else x ] for i, (x, dtype) in enumerate( - zip(fmt_columns, self.frame.dtypes, strict=True) + zip(fmt_columns, self.frame.dtypes, strict=False) ) ] return str_columns From ce141baf9759c2894464ad2c9fe61dac0d8658d9 Mon Sep 17 00:00:00 2001 From: Lirong Date: Sun, 28 Sep 2025 19:56:21 +0000 Subject: [PATCH 5/9] strict to be false for some --- pandas/io/parsers/base_parser.py | 2 +- pandas/io/xml.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/io/parsers/base_parser.py b/pandas/io/parsers/base_parser.py index 9b2d66625808b..abd440cbc0d81 100644 --- a/pandas/io/parsers/base_parser.py +++ b/pandas/io/parsers/base_parser.py @@ -330,7 +330,7 @@ def _agg_index(self, index) -> Index: names: Iterable = self.index_names else: names = itertools.cycle([None]) - for i, (arr, name) in enumerate(zip(index, names, strict=True)): + for i, (arr, name) in enumerate(zip(index, names, strict=False)): if self._should_parse_dates(i): arr = date_converter( arr, diff --git a/pandas/io/xml.py b/pandas/io/xml.py index 2773d2b72a8ee..97259c57bbf33 100644 --- a/pandas/io/xml.py +++ b/pandas/io/xml.py @@ -245,7 +245,7 @@ def _parse_nodes(self, elems: list[Any]) -> list[dict[str, str | None]]: **({el.tag: el.text} if el.text and not el.text.isspace() else {}), **{ nm: ch.text if ch.text else None - for nm, ch in zip(self.names, el.findall("*"), strict=True) + for nm, ch in zip(self.names, el.findall("*"), strict=False) }, } for el in elems From b70e14e97ea93439fa4e555200a777722db302de Mon Sep 17 00:00:00 2001 From: Lirong Date: Sun, 28 Sep 2025 20:31:30 +0000 Subject: [PATCH 6/9] strict to false --- pandas/io/parsers/c_parser_wrapper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/io/parsers/c_parser_wrapper.py b/pandas/io/parsers/c_parser_wrapper.py index e3f02d44facaa..e517647d071d6 100644 --- a/pandas/io/parsers/c_parser_wrapper.py +++ b/pandas/io/parsers/c_parser_wrapper.py @@ -317,7 +317,7 @@ def read( if self.usecols is None: self._check_data_length(names, alldata) - data = {k: v for k, (i, v) in zip(names, data_tups, strict=True)} + data = {k: v for k, (i, v) in zip(names, data_tups, strict=False)} date_data = self._do_date_conversions(names, data) index, column_names = self._make_index(alldata, names) From 3591b11c549465fe400192f52b354d2e1e9e933f Mon Sep 17 00:00:00 2001 From: Lirong Date: Sun, 28 Sep 2025 20:54:36 +0000 Subject: [PATCH 7/9] more more false --- pandas/io/formats/info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/io/formats/info.py b/pandas/io/formats/info.py index 441ffec7f2b73..89b5e45dbb3a2 100644 --- a/pandas/io/formats/info.py +++ b/pandas/io/formats/info.py @@ -869,7 +869,7 @@ def _get_gross_column_widths(self) -> Sequence[int]: return [ max(*widths) for widths in zip( - self.header_column_widths, body_column_widths, strict=True + self.header_column_widths, body_column_widths, strict=False ) ] From 3c2d0c0adacf3c71fc24530c3917e384468417f5 Mon Sep 17 00:00:00 2001 From: Lirong Date: Sun, 28 Sep 2025 21:33:33 +0000 Subject: [PATCH 8/9] false --- pandas/io/formats/excel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/io/formats/excel.py b/pandas/io/formats/excel.py index a5a3f62300575..d4d47253a5f82 100644 --- a/pandas/io/formats/excel.py +++ b/pandas/io/formats/excel.py @@ -795,7 +795,7 @@ def _format_hierarchical_rows(self) -> Iterable[ExcelCell]: level_lengths, self.df.index.levels, self.df.index.codes, - strict=True, + strict=False, ): values = levels.take( level_codes, From 3da45c30d5f14edd416642743450da3af69d4623 Mon Sep 17 00:00:00 2001 From: Lirong Date: Thu, 2 Oct 2025 00:03:50 +0000 Subject: [PATCH 9/9] update pyproject.toml --- pyproject.toml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 50b7203c438e0..c29cea9616aa7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -476,11 +476,6 @@ exclude = [ "pandas/core/sorting.py" = ["B905"] "pandas/core/strings/accessor.py" = ["B905"] "pandas/core/window/rolling.py" = ["B905"] -"pandas/plotting/_core.py" = ["B905"] -"pandas/plotting/_matplotlib/boxplot.py" = ["B905"] -"pandas/plotting/_matplotlib/core.py" = ["B905"] -"pandas/plotting/_matplotlib/hist.py" = ["B905"] -"pandas/plotting/_matplotlib/misc.py" = ["B905"] "pandas/_testing/asserters.py" = ["B905"] "pandas/_testing/_warnings.py" = ["B905"] "pandas/tests/apply/test_series_apply.py" = ["B905"]