Skip to content

Commit 88fb277

Browse files
Revert "REF: avoid having 0 in JoinUnit.indexers (pandas-dev#43592)"
This reverts commit eb643d7.
1 parent b0fe1f0 commit 88fb277

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

pandas/core/internals/concat.py

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

3+
import copy
34
import itertools
45
from typing import (
56
TYPE_CHECKING,
@@ -332,15 +333,12 @@ def _get_mgr_concatenation_plan(mgr: BlockManager, indexers: dict[int, np.ndarra
332333
)
333334
)
334335

335-
if not unit_no_ax0_reindexing:
336-
# create block from subset of columns
337-
# Note: Blocks with only 1 column will always have unit_no_ax0_reindexing,
338-
# so we will never get here with ExtensionBlock.
339-
blk = blk.getitem_block(ax0_blk_indexer)
336+
# Omit indexer if no item reindexing is required.
337+
if unit_no_ax0_reindexing:
338+
join_unit_indexers.pop(0, None)
339+
else:
340+
join_unit_indexers[0] = ax0_blk_indexer
340341

341-
# Assertions disabled for performance
342-
# assert blk._mgr_locs.as_slice == placements.as_slice
343-
# assert blk.shape[0] == shape[0]
344342
unit = JoinUnit(blk, shape, join_unit_indexers)
345343

346344
plan.append((placements, unit))
@@ -354,7 +352,6 @@ def __init__(self, block: Block, shape: Shape, indexers=None):
354352
# Note: block is None implies indexers is None, but not vice-versa
355353
if indexers is None:
356354
indexers = {}
357-
# we should *never* have `0 in indexers`
358355
self.block = block
359356
self.indexers = indexers
360357
self.shape = shape
@@ -606,11 +603,20 @@ def _trim_join_unit(join_unit: JoinUnit, length: int) -> JoinUnit:
606603
607604
Extra items that didn't fit are returned as a separate block.
608605
"""
609-
assert 0 not in join_unit.indexers
610-
extra_indexers = join_unit.indexers
606+
if 0 not in join_unit.indexers:
607+
extra_indexers = join_unit.indexers
608+
609+
if join_unit.block is None:
610+
extra_block = None
611+
else:
612+
extra_block = join_unit.block.getitem_block(slice(length, None))
613+
join_unit.block = join_unit.block.getitem_block(slice(length))
614+
else:
615+
extra_block = join_unit.block
611616

612-
extra_block = join_unit.block.getitem_block(slice(length, None))
613-
join_unit.block = join_unit.block.getitem_block(slice(length))
617+
extra_indexers = copy.copy(join_unit.indexers)
618+
extra_indexers[0] = extra_indexers[0][length:]
619+
join_unit.indexers[0] = join_unit.indexers[0][:length]
614620

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

0 commit comments

Comments
 (0)