Skip to content

Commit d284250

Browse files
authored
CLN: remove unnecessary name in stack_arrays (pandas-dev#39517)
1 parent 787d6f3 commit d284250

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

pandas/core/internals/managers.py

+10-17
Original file line numberDiff line numberDiff line change
@@ -1698,7 +1698,7 @@ def construction_error(tot_items, block_shape, axes, e=None):
16981698
# -----------------------------------------------------------------------
16991699

17001700

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

1719-
k = names[name_idx]
17201719
v = arrays[name_idx]
17211720

17221721
block_type = get_block_type(v)
1723-
items_dict[block_type.__name__].append((i, k, v))
1722+
items_dict[block_type.__name__].append((i, v))
17241723

17251724
blocks: List[Block] = []
17261725
if len(items_dict["FloatBlock"]):
@@ -1742,7 +1741,7 @@ def _form_blocks(arrays, names: Index, axes) -> List[Block]:
17421741
if len(items_dict["DatetimeTZBlock"]):
17431742
dttz_blocks = [
17441743
make_block(array, klass=DatetimeTZBlock, placement=i, ndim=2)
1745-
for i, _, array in items_dict["DatetimeTZBlock"]
1744+
for i, array in items_dict["DatetimeTZBlock"]
17461745
]
17471746
blocks.extend(dttz_blocks)
17481747

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

17601759
if len(items_dict["ExtensionBlock"]):
17611760
external_blocks = [
17621761
make_block(array, klass=ExtensionBlock, placement=i, ndim=2)
1763-
for i, _, array in items_dict["ExtensionBlock"]
1762+
for i, array in items_dict["ExtensionBlock"]
17641763
]
17651764

17661765
blocks.extend(external_blocks)
17671766

17681767
if len(items_dict["ObjectValuesExtensionBlock"]):
17691768
external_blocks = [
17701769
make_block(array, klass=ObjectValuesExtensionBlock, placement=i, ndim=2)
1771-
for i, _, array in items_dict["ObjectValuesExtensionBlock"]
1770+
for i, array in items_dict["ObjectValuesExtensionBlock"]
17721771
]
17731772

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

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

18191818

1820-
def _stack_arrays(tuples, dtype):
1819+
def _stack_arrays(tuples, dtype: np.dtype):
18211820

18221821
# fml
18231822
def _asarray_compat(x):
@@ -1826,16 +1825,10 @@ def _asarray_compat(x):
18261825
else:
18271826
return np.asarray(x)
18281827

1829-
def _shape_compat(x) -> Shape:
1830-
if isinstance(x, ABCSeries):
1831-
return (len(x),)
1832-
else:
1833-
return x.shape
1834-
1835-
placement, names, arrays = zip(*tuples)
1828+
placement, arrays = zip(*tuples)
18361829

18371830
first = arrays[0]
1838-
shape = (len(arrays),) + _shape_compat(first)
1831+
shape = (len(arrays),) + first.shape
18391832

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

0 commit comments

Comments
 (0)