Skip to content

s.diff reports Series[object] instead of bool for nullable types #1150

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

Open
MarcoGorelli opened this issue Mar 7, 2025 · 2 comments
Open

Comments

@MarcoGorelli
Copy link
Member

Describe the bug
the diff overload doesn't seem exactly right for nullable types

To Reproduce

import pandas as pd

s: "pd.Series[bool]" = pd.Series([True, False], dtype='bool[pyarrow]')
reveal_type(s)  # Type of "s" is "Series[bool]"
reveal_type(s.diff())  # Type of "s.diff()" is "Series[type[object]]"

Please complete the following information:

  • OS: [e.g. Windows, Linux, MacOS] linux
  • OS Version [e.g. 22]
  • python version 3.12
  • version of type checker pyright 1.1.396
  • version of installed pandas-stubs 2938805

Additional context
Add any other context about the problem here.

@loicdiridollou
Copy link
Contributor

I think the issue is also that at runtime the traditional bool and the bool from pyarrow behaves differently.
A diff on the traditional bool outputs a series of object so the current type hint is matching static and dynamic while using pyarrow’s version of bool then you would end up with a series of bool[pyarrow].
So in your example when you force the series by defining the type as pd.Series[bool] you loose the information that it is a pyarrow bool and not the standard bool.
Right now we don’t have an overload for pyarrow bool, could be worth trying that out and see how the typehinting behaves.

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Mar 7, 2025

Right now we don’t have an overload for pyarrow bool, could be worth trying that out and see how the typehinting behaves.

Creating the right different behaviors for using the nullable types versus non-nullable types would be a challenge. We have a similar issue if the dtype is Int64 versus int. Both are Series[int] in the stubs.

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

No branches or pull requests

3 participants