-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
STYLE: fix some consider-using-enumerate pylint warnings #49214
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
Conversation
96d8432
to
2b06d03
Compare
pandas/core/array_algos/take.py
Outdated
@@ -549,13 +549,11 @@ def _take_2d_multi_object( | |||
out[row_mask, :] = fill_value | |||
if col_needs: | |||
out[:, col_mask] = fill_value | |||
for i in range(len(row_idx)): | |||
for i, u_ in enumerate(row_idx): | |||
u_ = row_idx[i] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This u_
shouldn' be needed anymore I think
These should be refactored if possible |
pandas/core/reshape/reshape.py
Outdated
level.reverse() | ||
while level: | ||
lev = level.pop() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would lev = level.pop(0)
(without level.reverse
) work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM cc @MarcoGorelli merge when ready
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Moisan !
for index in range(len(level)): | ||
lev = level[index] | ||
while level: | ||
lev = level.pop(0) | ||
result = stack(result, lev, dropna=dropna) | ||
# Decrement all level numbers greater than current, as these | ||
# have now shifted down by one | ||
updated_level = [] | ||
for other in level: | ||
if other > lev: | ||
updated_level.append(other - 1) | ||
else: | ||
updated_level.append(other) | ||
level = updated_level | ||
level = [v if v <= lev else v - 1 for v in level] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Looks fine, and I ran
$ cat f.py
import numpy as np
for _ in range(10):
original_level = np.random.randint(0, 8, size=9)
main_lev_sequence = []
level = [i for i in original_level]
for index in range(len(level)):
lev = level[index]
main_lev_sequence.append(lev)
updated_level = []
for other in level:
if other > lev:
updated_level.append(other - 1)
else:
updated_level.append(other)
level = updated_level
branch_lev_sequence = []
level = [i for i in original_level]
while level:
lev = level.pop(0)
branch_lev_sequence.append(lev)
level = [v if v <= lev else v - 1 for v in level]
assert main_lev_sequence == branch_lev_sequence
to check, which worked
…49214) * STYLE: fix some consider-using-enumerate pylint errors * fixup! STYLE: fix some consider-using-enumerate pylint errors * fixup! fixup! STYLE: fix some consider-using-enumerate pylint errors * fixup! fixup! fixup! STYLE: fix some consider-using-enumerate pylint errors * fixup! fixup! fixup! fixup! STYLE: fix some consider-using-enumerate pylint errors
…49214) * STYLE: fix some consider-using-enumerate pylint errors * fixup! STYLE: fix some consider-using-enumerate pylint errors * fixup! fixup! STYLE: fix some consider-using-enumerate pylint errors * fixup! fixup! fixup! STYLE: fix some consider-using-enumerate pylint errors * fixup! fixup! fixup! fixup! STYLE: fix some consider-using-enumerate pylint errors
Related to #48855
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.This covers some
consider-using-enumerate
pylint warnings but not all them. The ones left are often using the index of the for-loop without accessing element of the list. Is that something we want to put an "ignore" tag on?