Skip to content
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

pandas droplevel missing some argument types #391

Closed
Dr-Irv opened this issue Sep 18, 2020 · 1 comment
Closed

pandas droplevel missing some argument types #391

Dr-Irv opened this issue Sep 18, 2020 · 1 comment
Assignees
Labels
fixed in next version (main) A fix has been implemented and will appear in an upcoming version typestub Issue relating to our bundled type stubs

Comments

@Dr-Irv
Copy link

Dr-Irv commented Sep 18, 2020

Environment data

  • Language Server version: 2020.9.5
  • OS and version: Windows 10
  • Python version (& distribution if applicable, e.g. Anaconda): Anaconda Python 3.7.5

Expected behaviour

No error

Actual behaviour

mi3 : pd.Index = pd.MultiIndex.from_product([[1, 2], [3, 4], [5, 6]], names=["a", "b", "c"])
mi4 = mi3.droplevel("a")
mi4 = mi3.droplevel(["a", "b"])
s = pd.Series([i for i in range(len(mi3))], index=mi3)
s2 = s.droplevel(["a", "b"])
df = s.to_frame("s")
df3 = df.droplevel(["a", "b"])

Get errors as follows on lines 2, 3, 5 and 7 respectively. droplevel() allows string and list of string arguments

Argument of type "Literal['a']" cannot be assigned to parameter "level" of type "int" in function "droplevel"
  "Literal['a']" is incompatible with "int"

Argument of type "List[str]" cannot be assigned to parameter "level" of type "int" in function "droplevel"
  "List[str]" is incompatible with "int"

Argument of type "List[str]" cannot be assigned to parameter "level" of type "Level" in function "droplevel"
  Type "List[str]" cannot be assigned to type "Level"
    "__hash__" is an incompatible type
    Cannot assign to "None"
    "List[str]" is incompatible with "int"
      Type "None" cannot be assigned to type "(self: Unknown) -> int"

Argument of type "List[str]" cannot be assigned to parameter "level" of type "Level" in function "droplevel"
  Type "List[str]" cannot be assigned to type "Level"
    "__hash__" is an incompatible type
    Cannot assign to "None"
    "List[str]" is incompatible with "int"
      Type "None" cannot be assigned to type "(self: Unknown) -> int"

Fixes are as follows:

diff core/frame.pyi.ORIG core/frame.pyi
2924c2925
<     def droplevel(self, level: Level = ..., axis: AxisType = ...) -> DataFrame: ...
---
>     def droplevel(self, level: Union[Level, List[Level]] = ..., axis: AxisType = ...) -> DataFrame: ...

diff core/series.pyi.ORIG core/series.pyi
1598c1599
<     def droplevel(self, level: Level, axis: SeriesAxisType = ...) -> DataFrame: ...
---
>     def droplevel(self, level: Union[Level, List[Level]], axis: SeriesAxisType = ...) -> DataFrame: ...

diff core/indexes/base.pyi.ORIG core/indexes/base.pyi
2c2
< from pandas._typing import Dtype, Label, T1, T2, np_ndarray_str, np_ndarray_int64
---
> from pandas._typing import Dtype, Label, Level, T1, T2, np_ndarray_str, np_ndarray_int64
76c76
<     def droplevel(self, level: int = ...): ...
---
>     def droplevel(self, level: Union[Label, List[Label]] = ...): ...
@jakebailey jakebailey added the bug Something isn't working label Sep 18, 2020
@github-actions github-actions bot removed the triage label Sep 18, 2020
@judej judej added typestub Issue relating to our bundled type stubs and removed bug Something isn't working labels Sep 21, 2020
@gramster gramster added the fixed in next version (main) A fix has been implemented and will appear in an upcoming version label Sep 22, 2020
@jakebailey
Copy link
Member

This issue has been fixed in version 2020.9.6, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/master/CHANGELOG.md#202096-23-september-2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed in next version (main) A fix has been implemented and will appear in an upcoming version typestub Issue relating to our bundled type stubs
Projects
None yet
Development

No branches or pull requests

4 participants