Skip to content

CLN: rename init_dict/ndarray to dict/ndarray_to_mgr for consistency #40074

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@
from pandas.core.internals.construction import (
arrays_to_mgr,
dataclasses_to_dicts,
init_dict,
init_ndarray,
dict_to_mgr,
masked_rec_array_to_mgr,
mgr_to_mgr,
ndarray_to_mgr,
nested_data_to_arrays,
reorder_arrays,
sanitize_index,
Expand Down Expand Up @@ -575,7 +575,7 @@ def __init__(
)

elif isinstance(data, dict):
mgr = init_dict(data, index, columns, dtype=dtype)
mgr = dict_to_mgr(data, index, columns, dtype=dtype)
elif isinstance(data, ma.MaskedArray):
import numpy.ma.mrecords as mrecords

Expand All @@ -586,19 +586,19 @@ def __init__(
# a masked array
else:
data = sanitize_masked_array(data)
mgr = init_ndarray(data, index, columns, dtype=dtype, copy=copy)
mgr = ndarray_to_mgr(data, index, columns, dtype=dtype, copy=copy)

elif isinstance(data, (np.ndarray, Series, Index)):
if data.dtype.names:
data_columns = list(data.dtype.names)
data = {k: data[k] for k in data_columns}
if columns is None:
columns = data_columns
mgr = init_dict(data, index, columns, dtype=dtype)
mgr = dict_to_mgr(data, index, columns, dtype=dtype)
elif getattr(data, "name", None) is not None:
mgr = init_dict({data.name: data}, index, columns, dtype=dtype)
mgr = dict_to_mgr({data.name: data}, index, columns, dtype=dtype)
else:
mgr = init_ndarray(data, index, columns, dtype=dtype, copy=copy)
mgr = ndarray_to_mgr(data, index, columns, dtype=dtype, copy=copy)

# For data is list-like, or Iterable (will consume into list)
elif is_list_like(data):
Expand All @@ -613,9 +613,9 @@ def __init__(
)
mgr = arrays_to_mgr(arrays, columns, index, columns, dtype=dtype)
else:
mgr = init_ndarray(data, index, columns, dtype=dtype, copy=copy)
mgr = ndarray_to_mgr(data, index, columns, dtype=dtype, copy=copy)
else:
mgr = init_dict({}, index, columns, dtype=dtype)
mgr = dict_to_mgr({}, index, columns, dtype=dtype)
# For data is scalar
else:
if index is None or columns is None:
Expand All @@ -638,7 +638,7 @@ def __init__(
data, len(index), len(columns), dtype, copy
)

mgr = init_ndarray(
mgr = ndarray_to_mgr(
values, index, columns, dtype=values.dtype, copy=False
)

Expand Down
7 changes: 5 additions & 2 deletions pandas/core/internals/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ def mgr_to_mgr(mgr, typ: str):
# DataFrame Constructor Interface


def init_ndarray(values, index, columns, dtype: Optional[DtypeObj], copy: bool):
def ndarray_to_mgr(values, index, columns, dtype: Optional[DtypeObj], copy: bool):
# used in DataFrame.__init__
# input must be a ndarray, list, Series, index

if isinstance(values, ABCSeries):
Expand Down Expand Up @@ -277,10 +278,12 @@ def init_ndarray(values, index, columns, dtype: Optional[DtypeObj], copy: bool):
return create_block_manager_from_blocks(block_values, [columns, index])


def init_dict(data: Dict, index, columns, dtype: Optional[DtypeObj] = None):
def dict_to_mgr(data: Dict, index, columns, dtype: Optional[DtypeObj] = None):
"""
Segregate Series based on type and coerce into matrices.
Needs to handle a lot of exceptional cases.

Used in DataFrame.__init__
"""
arrays: Union[Sequence[Any], Series]

Expand Down