Skip to content

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

Merged
merged 5 commits into from
Oct 21, 2022

Conversation

Moisan
Copy link
Contributor

@Moisan Moisan commented Oct 20, 2022

Related to #48855

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?

@Moisan Moisan changed the title STYLE: fix some consider-using-enumerate pylint errors STYLE: fix some consider-using-enumerate pylint warnings Oct 20, 2022
@@ -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]
Copy link
Member

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

@mroeschke mroeschke added the Code Style Code style, linting, code_checks label Oct 20, 2022
@mroeschke
Copy link
Member

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?

These should be refactored if possible

Comment on lines 638 to 640
level.reverse()
while level:
lev = level.pop()
Copy link
Member

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?

Copy link
Member

@mroeschke mroeschke left a 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

Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

Thanks @Moisan !

Comment on lines -639 to +642
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]
Copy link
Member

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

@MarcoGorelli MarcoGorelli added this to the 2.0 milestone Oct 21, 2022
@MarcoGorelli MarcoGorelli merged commit 93bd1a8 into pandas-dev:main Oct 21, 2022
phofl pushed a commit to phofl/pandas that referenced this pull request Oct 21, 2022
…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
@Moisan Moisan deleted the enumerate_pylint branch October 29, 2022 20:19
noatamir pushed a commit to noatamir/pandas that referenced this pull request Nov 9, 2022
…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
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