Skip to content

Commit

Permalink
REF: Separate out DataFrame/Series Construction Helpers (#24100)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel authored and jreback committed Dec 5, 2018
1 parent 6919013 commit 669cb27
Show file tree
Hide file tree
Showing 6 changed files with 756 additions and 706 deletions.
10 changes: 5 additions & 5 deletions pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,12 +380,12 @@ def __init__(self, values, categories=None, ordered=None, dtype=None,
dtype = CategoricalDtype(values.categories, dtype.ordered)

elif not isinstance(values, (ABCIndexClass, ABCSeries)):
# _sanitize_array coerces np.nan to a string under certain versions
# sanitize_array coerces np.nan to a string under certain versions
# of numpy
values = maybe_infer_to_datetimelike(values, convert_dates=True)
if not isinstance(values, np.ndarray):
values = _convert_to_list_like(values)
from pandas.core.series import _sanitize_array
from pandas.core.internals.construction import sanitize_array
# By convention, empty lists result in object dtype:
if len(values) == 0:
sanitize_dtype = 'object'
Expand All @@ -394,7 +394,7 @@ def __init__(self, values, categories=None, ordered=None, dtype=None,
null_mask = isna(values)
if null_mask.any():
values = [values[idx] for idx in np.where(~null_mask)[0]]
values = _sanitize_array(values, None, dtype=sanitize_dtype)
values = sanitize_array(values, None, dtype=sanitize_dtype)

if dtype.categories is None:
try:
Expand Down Expand Up @@ -2442,12 +2442,12 @@ def isin(self, values):
>>> s.isin(['lama'])
array([ True, False, True, False, True, False])
"""
from pandas.core.series import _sanitize_array
from pandas.core.internals.construction import sanitize_array
if not is_list_like(values):
raise TypeError("only list-like objects are allowed to be passed"
" to isin(), you passed a [{values_type}]"
.format(values_type=type(values).__name__))
values = _sanitize_array(values, None, None)
values = sanitize_array(values, None, None)
null_mask = np.asarray(isna(values))
code_values = self.categories.get_indexer(values)
code_values = code_values[null_mask | (code_values >= 0)]
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/arrays/sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,8 +631,8 @@ def __init__(self, data, sparse_index=None, index=None, fill_value=None,
if not is_array_like(data):
try:
# probably shared code in sanitize_series
from pandas.core.series import _sanitize_array
data = _sanitize_array(data, index=None)
from pandas.core.internals.construction import sanitize_array
data = sanitize_array(data, index=None)
except ValueError:
# NumPy may raise a ValueError on data like [1, []]
# we retry with object dtype here.
Expand Down
Loading

0 comments on commit 669cb27

Please sign in to comment.