Skip to content

Commit

Permalink
CLN: remove duplicated code
Browse files Browse the repository at this point in the history
  • Loading branch information
jreback committed May 31, 2017
1 parent 8871863 commit 91a0e5f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 91a0e5f

Please sign in to comment.