Open
Description
I'm preparing a PR that addresses the short-comings of core.dtypes.cast.maybe_promote
uncovered in #23982, and there's currently only a branch in there along the following lines:
def maybe_promote(dtype, fill_value)
[...]
elif is_extension_array_dtype(dtype) and isna(fill_value):
fill_value = dtype.na_value
[...]
return dtype, fill_value
This does not describe any promotion rules, and (like the rest of maybe_promote
) is very inconsistent about the returned missing value (see #23982).
My suggestion would be to to something like the following:
if is_extension_array_dtype(dtype):
# dispatch to EA
dtype.maybe_promote(fill_value)
which would let EA authors decide how to handle dtype promotions (this is relevant e.g. for #24020).
The default could be to always upcast to object, but in many cases, there would be clear conditions for what doesn't upcast (e.g. all integers in the new 'Int' dtypes).