Closed
Description
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