def maybe_upcast(values, fill_value=np.nan, dtype=None, copy=False):
if is_extension_type(values):<EOL><INDENT>if copy:<EOL><INDENT>values = values.copy()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if dtype is None:<EOL><INDENT>dtype = values.dtype<EOL><DEDENT>new_dtype, fill_value = maybe_promote(dtype, fill_value)<EOL>if new_dtype != values.dtype:<EOL><INDENT>values = values.astype(new_dtype)<EOL><DEDENT>elif copy:<EOL><INDENT>values = values.copy()<EOL><DEDENT><DEDENT>return values, fill_value<EOL>
provide explicit type promotion and coercion

    Parameters
    ----------
    values : the ndarray that we want to maybe upcast
    fill_value : what we want to fill with
    dtype : if None, then use the dtype of the values, else coerce to this type
    copy : if True always make a copy even if no upcast is required