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

Stack method - Unexpected keyword argument #925

Open
rinzool opened this issue May 15, 2024 · 2 comments
Open

Stack method - Unexpected keyword argument #925

rinzool opened this issue May 15, 2024 · 2 comments
Labels
Reshaping Concat, Merge/Join, Stack/Unstack, Explode

Comments

@rinzool
Copy link
Contributor

rinzool commented May 15, 2024

Describe the bug
Method .stack of dataframe is not fully typed, it misses argument sort and future_stack

To Reproduce

  1. Provide a minimal runnable pandas example that is not properly checked by the stubs.
import pandas as pd
df = pd.DataFrame([1, 2, 3])
df.stack(future_stack=True)
df.stack(sort=True)
  1. Indicate which type checker you are using (mypy or pyright).
    I am using mypy (1.10.0)
  2. Show the error message received from that type checker while checking your example.
ex.py:3: error: Unexpected keyword argument "future_stack" for "stack" of "DataFrame"  [call-arg]
ex.py:4: error: Unexpected keyword argument "sort" for "stack" of "DataFrame"  [call-arg]
Found 2 errors in 1 file (checked 1 source file)

Please complete the following information:

  • OS: ArchLinux
  • python version: 3.10.14
  • version of type checker: 1.10.0
  • version of installed pandas-stubs 2.2.2.240514

Additional context
I'll be glad to open a PR to add those two arguments with some tests if that's ok for you, but I'm not entirely sure about what is the philosophy about pandas-stubs here. Since they are new arguments in 2.1, could it be bad to add those arguments in pandas stubs for someone who sill uses 2.0?

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented May 15, 2024

I'll be glad to open a PR to add those two arguments with some tests if that's ok for you, but I'm not entirely sure about what is the philosophy about pandas-stubs here. Since they are new arguments in 2.1, could it be bad to add those arguments in pandas stubs for someone who sill uses 2.0?

Not a problem, because we only support the latest version of pandas in the stubs. Also, the arguments are optional, so anyone using an earlier version of pandas wouldn't be using them anyway.

Thanks for the report. Given that future_stack is incompatible with sort and dropna, you'd need overloads to show the possible combinations of the arguments.

PR with test welcome

@Dr-Irv Dr-Irv added the Reshaping Concat, Merge/Join, Stack/Unstack, Explode label May 15, 2024
@rinzool
Copy link
Contributor Author

rinzool commented May 15, 2024

Thanks @Dr-Irv for the @overload tips
I just opened a PR: #926
Locally pytest, pyright and mypy works as expected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

No branches or pull requests

2 participants