-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Open
Labels
Dtype ConversionsUnexpected or buggy dtype conversionsUnexpected or buggy dtype conversionsEnhancementExtensionArrayExtending pandas with custom dtypes or arrays.Extending pandas with custom dtypes or arrays.
Description
import numpy as np
import pandas as pd
ii = pd.interval_range(1, 10)
ser = pd.Series(ii).copy()
mask = np.zeros(ser.shape, dtype=bool)
mask[1] = True
ii.insert(1, np.nan) # <- IntervalDtype[float64]
ii.putmask(mask, np.nan) # <- IntervalDtype[float64]
ser.where(mask, np.nan) # <- ValueError
ser[1] = np.nan <- coerces to object
ATM dtypes.cast.ensure_dtype_can_hold_na
is incorrect for EA dtypes that cannot hold NA values (the IntervalDtype[int]
example is the only one that comes to mind).
We have special-casing for IntervalDtype in Index._find_common_type_compat
which is why the Index methods above behave well. Short-term, we can move that special-casing into ensure_dtype_can_hold_na
. Longer-term, we need a way for EADtype subclasses to specify this behavior.
This could be seen as a special case of xref #24246
Metadata
Metadata
Assignees
Labels
Dtype ConversionsUnexpected or buggy dtype conversionsUnexpected or buggy dtype conversionsEnhancementExtensionArrayExtending pandas with custom dtypes or arrays.Extending pandas with custom dtypes or arrays.