Skip to content

CLN: remove unnecessary name in stack_arrays #39517

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 2 commits into from
Feb 2, 2021
Merged
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
27 changes: 10 additions & 17 deletions pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1698,7 +1698,7 @@ def construction_error(tot_items, block_shape, axes, e=None):
# -----------------------------------------------------------------------


def _form_blocks(arrays, names: Index, axes) -> List[Block]:
def _form_blocks(arrays, names: Index, axes: List[Index]) -> List[Block]:
# put "leftover" items in float bucket, where else?
# generalize?
items_dict: DefaultDict[str, List] = defaultdict(list)
Expand All @@ -1716,11 +1716,10 @@ def _form_blocks(arrays, names: Index, axes) -> List[Block]:
extra_locs.append(i)
continue

k = names[name_idx]
v = arrays[name_idx]

block_type = get_block_type(v)
items_dict[block_type.__name__].append((i, k, v))
items_dict[block_type.__name__].append((i, v))

blocks: List[Block] = []
if len(items_dict["FloatBlock"]):
Expand All @@ -1742,7 +1741,7 @@ def _form_blocks(arrays, names: Index, axes) -> List[Block]:
if len(items_dict["DatetimeTZBlock"]):
dttz_blocks = [
make_block(array, klass=DatetimeTZBlock, placement=i, ndim=2)
for i, _, array in items_dict["DatetimeTZBlock"]
for i, array in items_dict["DatetimeTZBlock"]
]
blocks.extend(dttz_blocks)

Expand All @@ -1753,22 +1752,22 @@ def _form_blocks(arrays, names: Index, axes) -> List[Block]:
if len(items_dict["CategoricalBlock"]) > 0:
cat_blocks = [
make_block(array, klass=CategoricalBlock, placement=i, ndim=2)
for i, _, array in items_dict["CategoricalBlock"]
for i, array in items_dict["CategoricalBlock"]
]
blocks.extend(cat_blocks)

if len(items_dict["ExtensionBlock"]):
external_blocks = [
make_block(array, klass=ExtensionBlock, placement=i, ndim=2)
for i, _, array in items_dict["ExtensionBlock"]
for i, array in items_dict["ExtensionBlock"]
]

blocks.extend(external_blocks)

if len(items_dict["ObjectValuesExtensionBlock"]):
external_blocks = [
make_block(array, klass=ObjectValuesExtensionBlock, placement=i, ndim=2)
for i, _, array in items_dict["ObjectValuesExtensionBlock"]
for i, array in items_dict["ObjectValuesExtensionBlock"]
]

blocks.extend(external_blocks)
Expand Down Expand Up @@ -1804,7 +1803,7 @@ def _simple_blockify(tuples, dtype) -> List[Block]:
def _multi_blockify(tuples, dtype: Optional[Dtype] = None):
""" return an array of blocks that potentially have different dtypes """
# group by dtype
grouper = itertools.groupby(tuples, lambda x: x[2].dtype)
grouper = itertools.groupby(tuples, lambda x: x[1].dtype)

new_blocks = []
for dtype, tup_block in grouper:
Expand All @@ -1817,7 +1816,7 @@ def _multi_blockify(tuples, dtype: Optional[Dtype] = None):
return new_blocks


def _stack_arrays(tuples, dtype):
def _stack_arrays(tuples, dtype: np.dtype):

# fml
def _asarray_compat(x):
Expand All @@ -1826,16 +1825,10 @@ def _asarray_compat(x):
else:
return np.asarray(x)

def _shape_compat(x) -> Shape:
if isinstance(x, ABCSeries):
return (len(x),)
else:
return x.shape

placement, names, arrays = zip(*tuples)
placement, arrays = zip(*tuples)

first = arrays[0]
shape = (len(arrays),) + _shape_compat(first)
shape = (len(arrays),) + first.shape

stacked = np.empty(shape, dtype=dtype)
for i, arr in enumerate(arrays):
Expand Down