Skip to content

Commit d51ee22

Browse files
CLN: rename init_dict/ndarray to dict/ndarray_to_mgr for consistency (#40074)
1 parent 78371cc commit d51ee22

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

pandas/core/frame.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,10 @@
177177
from pandas.core.internals.construction import (
178178
arrays_to_mgr,
179179
dataclasses_to_dicts,
180-
init_dict,
181-
init_ndarray,
180+
dict_to_mgr,
182181
masked_rec_array_to_mgr,
183182
mgr_to_mgr,
183+
ndarray_to_mgr,
184184
nested_data_to_arrays,
185185
reorder_arrays,
186186
sanitize_index,
@@ -575,7 +575,7 @@ def __init__(
575575
)
576576

577577
elif isinstance(data, dict):
578-
mgr = init_dict(data, index, columns, dtype=dtype)
578+
mgr = dict_to_mgr(data, index, columns, dtype=dtype)
579579
elif isinstance(data, ma.MaskedArray):
580580
import numpy.ma.mrecords as mrecords
581581

@@ -586,19 +586,19 @@ def __init__(
586586
# a masked array
587587
else:
588588
data = sanitize_masked_array(data)
589-
mgr = init_ndarray(data, index, columns, dtype=dtype, copy=copy)
589+
mgr = ndarray_to_mgr(data, index, columns, dtype=dtype, copy=copy)
590590

591591
elif isinstance(data, (np.ndarray, Series, Index)):
592592
if data.dtype.names:
593593
data_columns = list(data.dtype.names)
594594
data = {k: data[k] for k in data_columns}
595595
if columns is None:
596596
columns = data_columns
597-
mgr = init_dict(data, index, columns, dtype=dtype)
597+
mgr = dict_to_mgr(data, index, columns, dtype=dtype)
598598
elif getattr(data, "name", None) is not None:
599-
mgr = init_dict({data.name: data}, index, columns, dtype=dtype)
599+
mgr = dict_to_mgr({data.name: data}, index, columns, dtype=dtype)
600600
else:
601-
mgr = init_ndarray(data, index, columns, dtype=dtype, copy=copy)
601+
mgr = ndarray_to_mgr(data, index, columns, dtype=dtype, copy=copy)
602602

603603
# For data is list-like, or Iterable (will consume into list)
604604
elif is_list_like(data):
@@ -613,9 +613,9 @@ def __init__(
613613
)
614614
mgr = arrays_to_mgr(arrays, columns, index, columns, dtype=dtype)
615615
else:
616-
mgr = init_ndarray(data, index, columns, dtype=dtype, copy=copy)
616+
mgr = ndarray_to_mgr(data, index, columns, dtype=dtype, copy=copy)
617617
else:
618-
mgr = init_dict({}, index, columns, dtype=dtype)
618+
mgr = dict_to_mgr({}, index, columns, dtype=dtype)
619619
# For data is scalar
620620
else:
621621
if index is None or columns is None:
@@ -638,7 +638,7 @@ def __init__(
638638
data, len(index), len(columns), dtype, copy
639639
)
640640

641-
mgr = init_ndarray(
641+
mgr = ndarray_to_mgr(
642642
values, index, columns, dtype=values.dtype, copy=False
643643
)
644644

pandas/core/internals/construction.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ def mgr_to_mgr(mgr, typ: str):
195195
# DataFrame Constructor Interface
196196

197197

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

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

279280

280-
def init_dict(data: Dict, index, columns, dtype: Optional[DtypeObj] = None):
281+
def dict_to_mgr(data: Dict, index, columns, dtype: Optional[DtypeObj] = None):
281282
"""
282283
Segregate Series based on type and coerce into matrices.
283284
Needs to handle a lot of exceptional cases.
285+
286+
Used in DataFrame.__init__
284287
"""
285288
arrays: Union[Sequence[Any], Series]
286289

0 commit comments

Comments
 (0)