Skip to content

na_value in to_numpy does not accept NumPy number types #1182

Closed
@vnmabus

Description

@vnmabus

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions