Skip to content

IndexSlice typing is no longer correct #300

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

Closed
Dr-Irv opened this issue Sep 15, 2022 · 0 comments · Fixed by #311
Closed

IndexSlice typing is no longer correct #300

Dr-Irv opened this issue Sep 15, 2022 · 0 comments · Fixed by #311
Assignees

Comments

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Sep 15, 2022

Describe the bug
Prior to #282, pd.IndexSlice returned a tuple with specific types. That is no longer the case.

To Reproduce

import pandas as pd

df = (
    pd.DataFrame({"x": [1, 2, 2, 3, 4], "y": [10, 20, 30, 40, 10]})
    .assign(z=lambda df: df.x * df.y)
    .set_index(["x", "y"])
)
ind = pd.Index([2, 3])
reveal_type(pd.IndexSlice[ind, :])

With pandas-stubs 1.4.4.220911, we get:

pyright reports:

isli.py:4:13 - information: Type of "pd.IndexSlice[ind, :]" is "tuple[Unknown, ...]"

mypy reports:

isli.py:4: note: Revealed type is "builtins.tuple[Any, ...]"

With pandas-stubs 1.4.4.220906, we get:

pyright:

isli.py:9:13 - information: Type of "pd.IndexSlice[ind, :]" is "tuple[str | str_ | bytes | date | datetime | timedelta | bool | complex | Timestamp | Timedelta | slice, ...]"

mypy:

isli.py:9: note: Revealed type is "builtins.tuple[Union[Union[builtins.str, numpy.str_], Union[builtins.str, builtins.bytes, datetime.date, datetime.datetime, datetime.timedelta, builtins.bool, builtins.complex, pandas._libs.tslibs.timestamps.Timestamp, pandas._libs.tslibs.timedeltas.Timedelta], builtins.slice], ...]"

Please complete the following information:

  • OS: Windows 10
  • python version: 3.10
  • mypy 0.971, pyright 1.269
  • version of installed pandas-stubs: 1.4.4.220911

Additional context

@bashtage needs to look at this, because change in #282 is what messed this up.

@Dr-Irv Dr-Irv assigned Dr-Irv and bashtage and unassigned Dr-Irv Sep 15, 2022
@Dr-Irv Dr-Irv mentioned this issue Sep 17, 2022
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants