-
-
Couldn't load subscription status.
- Fork 3k
Closed as not planned
Labels
Description
Feature
Id like to be able to write:
SeriesOfBool = NewType("SeriesOfBool", Annotated[pandas.Series, "bool"])
def is_series_of_bool(series: pandas.Series) -> TypeGuard[SeriesOfBool]:
return series.dtype == "bool"
Pitch
I would dearly love to track the data type of the many series values floating around my code. The above seems like a reasonable approach., which seems to work fine if I define ArrayOfBool = NewType("ArrayOfBool", Annotated[numpy.ndarray, "bool"]).
However because pandas has no type annotations, then pandas.Series is essentially Any and trying the above gives the error Argument 2 to NewType(...) must be subclassable (got "Any").
It seems like Annotated[Any, ...] shouldn't be the same as Any - in particular, not all values belong to the annotated type - so this error is over conservative?