Skip to content

Commit 590e20c

Browse files
jbrockmendelsimonjayhawkins
authored andcommitted
CLN: core.internals (#31179)
1 parent e83a6bd commit 590e20c

File tree

3 files changed

+10
-17
lines changed

3 files changed

+10
-17
lines changed

pandas/core/frame.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3610,12 +3610,12 @@ def reindexer(value):
36103610
# Explicitly copy here, instead of in sanitize_index,
36113611
# as sanitize_index won't copy an EA, even with copy=True
36123612
value = value.copy()
3613-
value = sanitize_index(value, self.index, copy=False)
3613+
value = sanitize_index(value, self.index)
36143614

36153615
elif isinstance(value, Index) or is_sequence(value):
36163616

36173617
# turn me into an ndarray
3618-
value = sanitize_index(value, self.index, copy=False)
3618+
value = sanitize_index(value, self.index)
36193619
if not isinstance(value, (np.ndarray, Index)):
36203620
if isinstance(value, list) and len(value) > 0:
36213621
value = maybe_convert_platform(value)

pandas/core/internals/blocks.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2994,7 +2994,6 @@ def make_block(values, placement, klass=None, ndim=None, dtype=None):
29942994

29952995
def _extend_blocks(result, blocks=None):
29962996
""" return a new extended blocks, given the result """
2997-
from pandas.core.internals import BlockManager
29982997

29992998
if blocks is None:
30002999
blocks = []
@@ -3004,9 +3003,8 @@ def _extend_blocks(result, blocks=None):
30043003
blocks.extend(r)
30053004
else:
30063005
blocks.append(r)
3007-
elif isinstance(result, BlockManager):
3008-
blocks.extend(result.blocks)
30093006
else:
3007+
assert isinstance(result, Block), type(result)
30103008
blocks.append(result)
30113009
return blocks
30123010

pandas/core/internals/construction.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def arrays_to_mgr(arrays, arr_names, index, columns, dtype=None):
7474
return create_block_manager_from_arrays(arrays, arr_names, axes)
7575

7676

77-
def masked_rec_array_to_mgr(data, index, columns, dtype, copy):
77+
def masked_rec_array_to_mgr(data, index, columns, dtype, copy: bool):
7878
"""
7979
Extract from a masked rec array and create the manager.
8080
"""
@@ -143,7 +143,7 @@ def init_ndarray(values, index, columns, dtype=None, copy=False):
143143
):
144144

145145
if not hasattr(values, "dtype"):
146-
values = prep_ndarray(values, copy=copy)
146+
values = _prep_ndarray(values, copy=copy)
147147
values = values.ravel()
148148
elif copy:
149149
values = values.copy()
@@ -166,7 +166,7 @@ def init_ndarray(values, index, columns, dtype=None, copy=False):
166166

167167
# by definition an array here
168168
# the dtypes will be coerced to a single dtype
169-
values = prep_ndarray(values, copy=copy)
169+
values = _prep_ndarray(values, copy=copy)
170170

171171
if dtype is not None:
172172
if not is_dtype_equal(values.dtype, dtype):
@@ -257,7 +257,7 @@ def init_dict(data, index, columns, dtype=None):
257257
# ---------------------------------------------------------------------
258258

259259

260-
def prep_ndarray(values, copy=True) -> np.ndarray:
260+
def _prep_ndarray(values, copy: bool = True) -> np.ndarray:
261261
if not isinstance(values, (np.ndarray, ABCSeries, Index)):
262262
if len(values) == 0:
263263
return np.empty((0, 0), dtype=object)
@@ -598,29 +598,24 @@ def convert(arr):
598598
# Series-Based
599599

600600

601-
def sanitize_index(data, index, copy=False):
601+
def sanitize_index(data, index: Index):
602602
"""
603603
Sanitize an index type to return an ndarray of the underlying, pass
604604
through a non-Index.
605605
"""
606606

607-
if index is None:
608-
return data
609-
610607
if len(data) != len(index):
611608
raise ValueError("Length of values does not match length of index")
612609

613-
if isinstance(data, ABCIndexClass) and not copy:
610+
if isinstance(data, ABCIndexClass):
614611
pass
615612
elif isinstance(data, (ABCPeriodIndex, ABCDatetimeIndex)):
616613
data = data._values
617-
if copy:
618-
data = data.copy()
619614

620615
elif isinstance(data, np.ndarray):
621616

622617
# coerce datetimelike types
623618
if data.dtype.kind in ["M", "m"]:
624-
data = sanitize_array(data, index, copy=copy)
619+
data = sanitize_array(data, index, copy=False)
625620

626621
return data

0 commit comments

Comments
 (0)