Skip to content
Merged
4 changes: 3 additions & 1 deletion pandas/io/excel/_xlrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
]
2 changes: 1 addition & 1 deletion pandas/io/formats/css.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions pandas/io/formats/excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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):
Expand Down
13 changes: 8 additions & 5 deletions pandas/io/formats/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 = [
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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))
Expand Down Expand Up @@ -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

Expand Down
13 changes: 9 additions & 4 deletions pandas/io/formats/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this False?

strict=True,
)
)
row = []
row.extend(idx_values[i])
Expand Down
23 changes: 14 additions & 9 deletions pandas/io/formats/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]:
Expand All @@ -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)
Expand All @@ -909,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
)
]
)
Expand All @@ -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)
Expand Down Expand Up @@ -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]]:
Expand All @@ -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]:
Expand Down Expand Up @@ -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]:
Expand Down
10 changes: 6 additions & 4 deletions pandas/io/formats/printing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions pandas/io/formats/style_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions pandas/io/json/_normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/json/_table_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pandas/io/parsers/base_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -330,7 +330,7 @@ def _agg_index(self, index) -> Index:
names: Iterable = self.index_names
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
names: Iterable = self.index_names
names: Iterable = self.index_names
strict = True

else:
names = itertools.cycle([None])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
names = itertools.cycle([None])
names = itertools.cycle([None])
strict = False

for i, (arr, name) in enumerate(zip(index, names)):
for i, (arr, name) in enumerate(zip(index, names, strict=True)):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for i, (arr, name) in enumerate(zip(index, names, strict=True)):
for i, (arr, name) in enumerate(zip(index, names, strict=strict)):

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Alvaro-Kothe I made the changes per your request.

if self._should_parse_dates(i):
arr = date_converter(
arr,
Expand Down
4 changes: 2 additions & 2 deletions pandas/io/parsers/c_parser_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pandas/io/parsers/python_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
):
Expand Down Expand Up @@ -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]:
Expand Down
Loading
Loading