Skip to content

TYP: fix incorrect mypy error in reshape.py #45127

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 3 commits into from
Dec 31, 2021

Conversation

kashifkhan
Copy link
Contributor

xref #37715

new_levels is not defined as a FrozenList within get_new_colums

# error: Incompatible types in assignment (expression has type "List[Any]",
# variable has type "FrozenList")
new_levels = [ # type: ignore[assignment]
new_levels = [
Copy link
Member

Choose a reason for hiding this comment

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

value_columns.levels has type FrozenList. In general: Mypy complains if we have unused ignore comments

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah missed seeing that during my review. Ill close this PR, thanks

Copy link
Member

Choose a reason for hiding this comment

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

@kashifkhan you might be able to get rid of the # type: ignore comment by annotating new_levels where it's defined (line 320)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MarcoGorelli hmm I can do that, but then on line 327 new_levels can also be a List of Index.

My current thought is to annotate new_levels to be a FrozenList on line 320 and then have a new variable new_levels_list as a List[Index] on line 327 . Then change the return statement based on which one is populated ...thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

You can just use new_levels: FrozenList | list[Index] I think?

Copy link
Member

Choose a reason for hiding this comment

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

or sequence[Index] if it doesn't need to be a list?

Copy link
Member

Choose a reason for hiding this comment

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

I think a Sequence should be ok, but since we are only using the variable only within the function we should narrow the type down?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@phofl went with list since it is only generated within the function & then passed on to the MultiIndex constructor which needs an Iterable.

@jreback jreback added the Typing type annotations, mypy/pyright type checking label Dec 30, 2021
@kashifkhan kashifkhan force-pushed the fix_mypy_err_reshape.py branch from 58417cf to 1fc040f Compare December 30, 2021 22:59
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 @kashifkhan

@jreback jreback added this to the 1.4 milestone Dec 31, 2021
@jreback jreback merged commit fa3d5f1 into pandas-dev:master Dec 31, 2021
@jreback
Copy link
Contributor

jreback commented Dec 31, 2021

thanks @kashifkhan

@kashifkhan kashifkhan deleted the fix_mypy_err_reshape.py branch December 31, 2021 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Typing type annotations, mypy/pyright type checking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants