def coerce_to_array(values, dtype, mask=None, copy=False):
<EOL>if dtype is None and hasattr(values, '<STR_LIT>'):<EOL><INDENT>if is_integer_dtype(values.dtype):<EOL><INDENT>dtype = values.dtype<EOL><DEDENT><DEDENT>if dtype is not None:<EOL><INDENT>if (isinstance(dtype, str) and<EOL>(dtype.startswith("<STR_LIT>") or dtype.startswith("<STR_LIT>"))):<EOL><INDENT>dtype = dtype.lower()<EOL><DEDENT>if not issubclass(type(dtype), _IntegerDtype):<EOL><INDENT>try:<EOL><INDENT>dtype = _dtypes[str(np.dtype(dtype))]<EOL><DEDENT>except KeyError:<EOL><INDENT>raise ValueError("<STR_LIT>".format(dtype))<EOL><DEDENT><DEDENT><DEDENT>if isinstance(values, IntegerArray):<EOL><INDENT>values, mask = values._data, values._mask<EOL>if dtype is not None:<EOL><INDENT>values = values.astype(dtype.numpy_dtype, copy=False)<EOL><DEDENT>if copy:<EOL><INDENT>values = values.copy()<EOL>mask = mask.copy()<EOL><DEDENT>return values, mask<EOL><DEDENT>values = np.array(values, copy=copy)<EOL>if is_object_dtype(values):<EOL><INDENT>inferred_type = lib.infer_dtype(values, skipna=True)<EOL>if inferred_type == '<STR_LIT>':<EOL><INDENT>values = np.empty(len(values))<EOL>values.fill(np.nan)<EOL><DEDENT>elif inferred_type not in ['<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>raise TypeError("<STR_LIT>".format(<EOL>values.dtype))<EOL><DEDENT><DEDENT>elif not (is_integer_dtype(values) or is_float_dtype(values)):<EOL><INDENT>raise TypeError("<STR_LIT>".format(<EOL>values.dtype))<EOL><DEDENT>if mask is None:<EOL><INDENT>mask = isna(values)<EOL><DEDENT>else:<EOL><INDENT>assert len(mask) == len(values)<EOL><DEDENT>if not values.ndim == <NUM_LIT:1>:<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if not mask.ndim == <NUM_LIT:1>:<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if dtype is None:<EOL><INDENT>dtype = np.dtype('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>dtype = dtype.type<EOL><DEDENT>if mask.any():<EOL><INDENT>values = values.copy()<EOL>values[mask] = <NUM_LIT:1><EOL>values = safe_cast(values, dtype, copy=False)<EOL><DEDENT>else:<EOL><INDENT>values = safe_cast(values, dtype, copy=False)<EOL><DEDENT>return values, mask<EOL>
Coerce the input values array to numpy arrays with a mask

Parameters
----------
values : 1D list-like
dtype : integer dtype
mask : boolean 1D array, optional
copy : boolean, default False
    if True, copy the input

Returns
-------
tuple of (values, mask)