-
- Notifications
You must be signed in to change notification settings - Fork 19.4k
Closed
Labels
CategoricalCategorical Data TypeCategorical Data TypePerformanceMemory or execution speed performanceMemory or execution speed performance
Description
In pd.isna, we convert instances of pd.Categorical a numpy array:
pandas/pandas/core/dtypes/missing.py
Lines 64 to 65 in 07d8c2d
| elif isinstance(obj, list) or hasattr(obj, '__array__'): | |
| return _isna_ndarraylike(np.asarray(obj)) |
We should be able to avoid that by calling obj.values.isna(), which just operates on the codes. To summarize:
pd.isna(Categorical(...))coercesDataFrame.isna/ coercesSeries.isna/pd.isna(series)is fine, we handle that aboveCategorical(...).isnais fine
So the cases to handle:
>>> s = pd.Categorical(['a', 'b']) >>> pd.isna(s) >>> pd.isna(pd.DataFrame({'A': s})) >>> pd.DataFrame({"A": s}).isna()Metadata
Metadata
Assignees
Labels
CategoricalCategorical Data TypeCategorical Data TypePerformanceMemory or execution speed performanceMemory or execution speed performance