Skip to content

Enable pylint undefined-loop-variable warning #50961

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pandas/core/util/hashing.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,14 @@ def combine_hash_arrays(

mult = np.uint64(1000003)
out = np.zeros_like(first) + np.uint64(0x345678)
last_i = 0
for i, a in enumerate(arrays):
inverse_i = num_items - i
out ^= a
out *= mult
mult += np.uint64(82520 + inverse_i + inverse_i)
assert i + 1 == num_items, "Fed in wrong num_items"
last_i = i
assert last_i + 1 == num_items, "Fed in wrong num_items"
out += np.uint64(97531)
return out

Expand Down
7 changes: 6 additions & 1 deletion pandas/io/excel/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,9 @@ def parse(

output = {}

last_sheetname = None
for asheetname in sheets:
last_sheetname = asheetname
if verbose:
print(f"Reading sheet {asheetname}")

Expand Down Expand Up @@ -888,10 +890,13 @@ def parse(
err.args = (f"{err.args[0]} (sheet: {asheetname})", *err.args[1:])
raise err

if last_sheetname is None:
raise ValueError("Sheet name is an empty list")

if ret_dict:
return output
else:
return output[asheetname]
return output[last_sheetname]


@doc(storage_options=_shared_docs["storage_options"])
Expand Down
10 changes: 7 additions & 3 deletions pandas/tests/frame/methods/test_to_dict_of_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,34 @@ def test_copy_blocks(self, float_frame):
column = df.columns[0]

# use the default copy=True, change a column
_last_df = None
blocks = df._to_dict_of_blocks(copy=True)
for _df in blocks.values():
_last_df = _df
if column in _df:
_df.loc[:, column] = _df[column] + 1

# make sure we did not change the original DataFrame
assert not _df[column].equals(df[column])
assert _last_df is not None and not _last_df[column].equals(df[column])

def test_no_copy_blocks(self, float_frame, using_copy_on_write):
# GH#9607
df = DataFrame(float_frame, copy=True)
column = df.columns[0]

_last_df = None
# use the copy=False, change a column
blocks = df._to_dict_of_blocks(copy=False)
for _df in blocks.values():
_last_df = _df
if column in _df:
_df.loc[:, column] = _df[column] + 1

if not using_copy_on_write:
# make sure we did change the original DataFrame
assert _df[column].equals(df[column])
assert _last_df is not None and _last_df[column].equals(df[column])
else:
assert not _df[column].equals(df[column])
assert _last_df is not None and not _last_df[column].equals(df[column])


def test_to_dict_of_blocks_item_cache(request, using_copy_on_write):
Expand Down
6 changes: 4 additions & 2 deletions pandas/tests/io/formats/test_printing.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,22 +122,24 @@ class TestTableSchemaRepr:
def test_publishes(self, ip):
ipython = ip.instance(config=ip.config)
df = pd.DataFrame({"A": [1, 2]})
objects = [df["A"], df, df] # dataframe / series
objects = [df["A"], df] # dataframe / series
expected_keys = [
{"text/plain", "application/vnd.dataresource+json"},
{"text/plain", "text/html", "application/vnd.dataresource+json"},
]

opt = pd.option_context("display.html.table_schema", True)
last_obj = None
for obj, expected in zip(objects, expected_keys):
last_obj = obj
with opt:
formatted = ipython.display_formatter.format(obj)
assert set(formatted[0].keys()) == expected

with_latex = pd.option_context("styler.render.repr", "latex")

with opt, with_latex:
formatted = ipython.display_formatter.format(obj)
formatted = ipython.display_formatter.format(last_obj)

expected = {
"text/plain",
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ disable = [
"too-many-public-methods",
"too-many-return-statements",
"too-many-statements",
"undefined-loop-variable",
"unexpected-keyword-arg",
"ungrouped-imports",
"unsubscriptable-object",
Expand Down