Skip to content

Commit eb643d7

Browse files
authored
REF: avoid having 0 in JoinUnit.indexers (pandas-dev#43592)
1 parent fae9f8c commit eb643d7

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

pandas/core/internals/concat.py

+11-19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
import copy
43
import itertools
54
from typing import (
65
TYPE_CHECKING,
@@ -330,12 +329,13 @@ def _get_mgr_concatenation_plan(mgr: BlockManager, indexers: dict[int, np.ndarra
330329
)
331330
)
332331

333-
# Omit indexer if no item reindexing is required.
334-
if unit_no_ax0_reindexing:
335-
join_unit_indexers.pop(0, None)
336-
else:
337-
join_unit_indexers[0] = ax0_blk_indexer
332+
if not unit_no_ax0_reindexing:
333+
# create block from subset of columns
334+
blk = blk.getitem_block(ax0_blk_indexer)
338335

336+
# Assertions disabled for performance
337+
# assert blk._mgr_locs.as_slice == placements.as_slice
338+
# assert blk.shape[0] == shape[0]
339339
unit = JoinUnit(blk, shape, join_unit_indexers)
340340

341341
plan.append((placements, unit))
@@ -349,6 +349,7 @@ def __init__(self, block: Block, shape: Shape, indexers=None):
349349
# Note: block is None implies indexers is None, but not vice-versa
350350
if indexers is None:
351351
indexers = {}
352+
# we should *never* have `0 in indexers`
352353
self.block = block
353354
self.indexers = indexers
354355
self.shape = shape
@@ -599,20 +600,11 @@ def _trim_join_unit(join_unit: JoinUnit, length: int) -> JoinUnit:
599600
600601
Extra items that didn't fit are returned as a separate block.
601602
"""
602-
if 0 not in join_unit.indexers:
603-
extra_indexers = join_unit.indexers
604-
605-
if join_unit.block is None:
606-
extra_block = None
607-
else:
608-
extra_block = join_unit.block.getitem_block(slice(length, None))
609-
join_unit.block = join_unit.block.getitem_block(slice(length))
610-
else:
611-
extra_block = join_unit.block
603+
assert 0 not in join_unit.indexers
604+
extra_indexers = join_unit.indexers
612605

613-
extra_indexers = copy.copy(join_unit.indexers)
614-
extra_indexers[0] = extra_indexers[0][length:]
615-
join_unit.indexers[0] = join_unit.indexers[0][:length]
606+
extra_block = join_unit.block.getitem_block(slice(length, None))
607+
join_unit.block = join_unit.block.getitem_block(slice(length))
616608

617609
extra_shape = (join_unit.shape[0] - length,) + join_unit.shape[1:]
618610
join_unit.shape = (length,) + join_unit.shape[1:]

0 commit comments

Comments
 (0)