def _ensure_data(values, dtype=None):
<EOL>try:<EOL><INDENT>if is_object_dtype(dtype):<EOL><INDENT>return ensure_object(np.asarray(values)), '<STR_LIT:object>', '<STR_LIT:object>'<EOL><DEDENT>if is_bool_dtype(values) or is_bool_dtype(dtype):<EOL><INDENT>return np.asarray(values).astype('<STR_LIT>'), '<STR_LIT:bool>', '<STR_LIT>'<EOL><DEDENT>elif is_signed_integer_dtype(values) or is_signed_integer_dtype(dtype):<EOL><INDENT>return ensure_int64(values), '<STR_LIT>', '<STR_LIT>'<EOL><DEDENT>elif (is_unsigned_integer_dtype(values) or<EOL>is_unsigned_integer_dtype(dtype)):<EOL><INDENT>return ensure_uint64(values), '<STR_LIT>', '<STR_LIT>'<EOL><DEDENT>elif is_float_dtype(values) or is_float_dtype(dtype):<EOL><INDENT>return ensure_float64(values), '<STR_LIT>', '<STR_LIT>'<EOL><DEDENT>elif is_object_dtype(values) and dtype is None:<EOL><INDENT>return ensure_object(np.asarray(values)), '<STR_LIT:object>', '<STR_LIT:object>'<EOL><DEDENT>elif is_complex_dtype(values) or is_complex_dtype(dtype):<EOL><INDENT>with catch_warnings():<EOL><INDENT>simplefilter("<STR_LIT:ignore>", np.ComplexWarning)<EOL>values = ensure_float64(values)<EOL><DEDENT>return values, '<STR_LIT>', '<STR_LIT>'<EOL><DEDENT><DEDENT>except (TypeError, ValueError, OverflowError):<EOL><INDENT>return ensure_object(values), '<STR_LIT:object>', '<STR_LIT:object>'<EOL><DEDENT>if (needs_i8_conversion(values) or<EOL>is_period_dtype(dtype) or<EOL>is_datetime64_any_dtype(dtype) or<EOL>is_timedelta64_dtype(dtype)):<EOL><INDENT>if is_period_dtype(values) or is_period_dtype(dtype):<EOL><INDENT>from pandas import PeriodIndex<EOL>values = PeriodIndex(values)<EOL>dtype = values.dtype<EOL><DEDENT>elif is_timedelta64_dtype(values) or is_timedelta64_dtype(dtype):<EOL><INDENT>from pandas import TimedeltaIndex<EOL>values = TimedeltaIndex(values)<EOL>dtype = values.dtype<EOL><DEDENT>else:<EOL><INDENT>from pandas import DatetimeIndex<EOL>values = DatetimeIndex(values)<EOL>dtype = values.dtype<EOL><DEDENT>return values.asi8, dtype, '<STR_LIT>'<EOL><DEDENT>elif (is_categorical_dtype(values) and<EOL>(is_categorical_dtype(dtype) or dtype is None)):<EOL><INDENT>values = getattr(values, '<STR_LIT>', values)<EOL>values = values.codes<EOL>dtype = '<STR_LIT>'<EOL>values = ensure_int64(values)<EOL>return values, dtype, '<STR_LIT>'<EOL><DEDENT>values = np.asarray(values, dtype=np.object)<EOL>return ensure_object(values), '<STR_LIT:object>', '<STR_LIT:object>'<EOL>
routine to ensure that our data is of the correct
input dtype for lower-level routines

This will coerce:
- ints -> int64
- uint -> uint64
- bool -> uint64 (TODO this should be uint8)
- datetimelike -> i8
- datetime64tz -> i8 (in local tz)
- categorical -> codes

Parameters
----------
values : array-like
dtype : pandas_dtype, optional
    coerce to this dtype

Returns
-------
(ndarray, pandas_dtype, algo dtype as a string)