Skip to content

na_value in to_numpy does not accept NumPy number types #1182

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
vnmabus opened this issue Apr 12, 2025 · 2 comments
Open

na_value in to_numpy does not accept NumPy number types #1182

vnmabus opened this issue Apr 12, 2025 · 2 comments

Comments

@vnmabus
Copy link

vnmabus commented Apr 12, 2025

Describe the bug
Calling to_numpy with na_value set to a NumPy type gives a type error. This works at runtime.

To Reproduce

  1. Provide a minimal runnable pandas example that is not properly checked by the stubs.

    import numpy as np
    import pandas as pd
    
    data_array = pd.arrays.IntegerArray(
        np.array([1, 2, -1], dtype=np.int32),
        mask=np.array([0, 0, 1], dtype=np.bool),
    )
    data = data_array.to_numpy(
        dtype=np.int32,
        na_value=np.int32(42),
    )
  2. Indicate which type checker you are using (mypy or pyright).

    I am using MyPy.

  3. Show the error message received from that type checker while checking your example.

    Argument "na_value" to "to_numpy" of "BaseMaskedArray" has incompatible type "signedinteger[_32Bit]"; expected "str | bytes | date | datetime | timedelta | <7 more items> | complex"
    

Please complete the following information:

  • OS: Windows
  • OS Version: 11
  • python version: 3.11.11
  • version of type checker: 1.15.0
  • version of installed pandas-stubs: 2.2.3.250308
@loicdiridollou
Copy link
Contributor

Thanks for the report!
This is indeed a known issue because Scalar type does not contain any of the numpy variations (np.int, np.float, ...).
It is currently up to consideration with @Dr-Irv because including those would have a large impact over the codebase but this may be the right way to go.

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Apr 14, 2025

I don't have an issue with adding np.float and np.int to the Scalar type in _typing.pyi, assuming it doesn't break anything else.

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