Skip to content

Conversation

LirongMa
Copy link
Contributor

@LirongMa LirongMa commented Sep 26, 2025

Add strict to zip() call for #62434

Copy link
Contributor

@Alvaro-Kothe Alvaro-Kothe left a comment

Choose a reason for hiding this comment

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

This should fix the problem.

Also, remove the files you modified from pyproject.toml.

pandas/pyproject.toml

Lines 435 to 438 in 179258f

# TODO: Fix B905 (zip-without-explicit-strict) - Remove files below as they're fixed
# For contributors working on this issue:
# After adding strict={True,False} to zip() calls in a file,
# remove its line from this section

clean_dtypes = self._clean_mapping(self.dtype)

if self.index_names is not None:
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

if self.index_names is not None:
names: Iterable = self.index_names
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

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)):
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.

shivamvishal added a commit to shivamvishal/pandas that referenced this pull request Sep 27, 2025
@LirongMa LirongMa changed the title Zip Strict for pandas/io [Issue #62434] - Enforce Ruff rule B905, zip-without-explicit-strict for pandas/io Sep 28, 2025
@LirongMa LirongMa changed the title [Issue #62434] - Enforce Ruff rule B905, zip-without-explicit-strict for pandas/io [Issue #62434] - ZIP strict for pandas/io Oct 2, 2025
@LirongMa LirongMa changed the title [Issue #62434] - ZIP strict for pandas/io STY: ZIP strict for pandas/io Oct 3, 2025
@LirongMa LirongMa requested a review from Alvaro-Kothe October 4, 2025 09:13
shivamvishal added a commit to shivamvishal/pandas that referenced this pull request Oct 4, 2025
Copy link
Contributor

@Alvaro-Kothe Alvaro-Kothe left a comment

Choose a reason for hiding this comment

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

Looking good overall. Just need to know why you had to use strict=False in some places.

]
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=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?

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?

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=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?

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=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 this one needs to be False, and the one above doesn't?

**{
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=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?

level_lengths,
self.df.index.levels,
self.df.index.codes,
strict=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?

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 the tests failed on these calls. Once I changed to False, all tests passed.

Copy link
Contributor

@Alvaro-Kothe Alvaro-Kothe left a comment

Choose a reason for hiding this comment

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

LGTM

@mroeschke mroeschke added the Code Style Code style, linting, code_checks label Oct 4, 2025
@mroeschke mroeschke added this to the 3.0 milestone Oct 4, 2025
@mroeschke mroeschke merged commit f570026 into pandas-dev:main Oct 4, 2025
89 checks passed
@mroeschke
Copy link
Member

Thanks @LirongMa

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code Style Code style, linting, code_checks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants