-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
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
TYP: fix incorrect mypy error in reshape.py #45127
Conversation
# error: Incompatible types in assignment (expression has type "List[Any]", | ||
# variable has type "FrozenList") | ||
new_levels = [ # type: ignore[assignment] | ||
new_levels = [ |
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.
value_columns.levels
has type FrozenList
. In general: Mypy complains if we have unused ignore comments
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.
ah missed seeing that during my review. Ill close this PR, thanks
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.
@kashifkhan you might be able to get rid of the # type: ignore
comment by annotating new_levels
where it's defined (line 320)
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.
@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?
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.
You can just use new_levels: FrozenList | list[Index]
I think?
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.
or sequence[Index]
if it doesn't need to be a list?
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.
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?
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.
@phofl went with list since it is only generated within the function & then passed on to the MultiIndex constructor which needs an Iterable.
58417cf
to
1fc040f
Compare
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 @kashifkhan
thanks @kashifkhan |
xref #37715
new_levels
is not defined as aFrozenList
withinget_new_colums