Skip to content

ENH: Expose pandas._libs.missing.NAType #48388

Closed
@randolf-scholz

Description

@randolf-scholz

Feature Type

  • Adding new functionality to pandas

  • Changing existing functionality in pandas

  • Removing existing functionality in pandas

Problem Description

When typing hinting using pandas-stubs, using type[pd.NA] is not possible.

error: Variable "pandas._libs.missing.NA" is not valid as a type  [valid-type]

Instead, it needs to be annotated as NAType which is currently hidden in the private library pandas._libs.missing.

Feature Description

Make NAType accessible through from pandas import NAType.

Alternative Solutions

Rework how padnas.NA works such that type[pandas.NA] is a valid type hint.

Additional Context

Example

import pandas as pd

def first_negative(s: Series[float]) -> float | type[pd.NA]:
    """return the first negative number in s or pd.NA""""
    negs = s[s<0]
    return negs[0] if len(negs) else pd.NA

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementNeeds TriageIssue that has not been reviewed by a pandas team memberTypingtype annotations, mypy/pyright type checking

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions