diff --git a/pandas/core/algorithms.py b/pandas/core/algorithms.py index d74c5e66ea1a9..16bb92f3706ef 100644 --- a/pandas/core/algorithms.py +++ b/pandas/core/algorithms.py @@ -64,6 +64,10 @@ def _ensure_data(values, dtype=None): """ + # short-circuit on object dtype requested + if is_object_dtype(dtype): + return _ensure_object(values), 'object', 'object' + # we check some simple dtypes first try: if is_bool_dtype(values) or is_bool_dtype(dtype): @@ -161,6 +165,7 @@ def _ensure_arraylike(values): """ if not isinstance(values, (np.ndarray, ABCCategorical, ABCIndexClass, ABCSeries)): + values = list(values) inferred = lib.infer_dtype(values) if inferred in ['mixed', 'string', 'unicode']: values = lib.list_to_object_array(values) @@ -392,10 +397,9 @@ def isin(comps, values): " to isin(), you passed a " "[{0}]".format(type(values).__name__)) - if not isinstance(values, (ABCIndex, ABCSeries, np.ndarray)): - values = lib.list_to_object_array(list(values)) - + comps = _ensure_arraylike(comps) comps, dtype, _ = _ensure_data(comps) + values = _ensure_arraylike(values) values, _, _ = _ensure_data(values, dtype=dtype) # GH11232