1
1
from __future__ import annotations
2
2
3
- import copy
4
3
import itertools
5
4
from typing import (
6
5
TYPE_CHECKING ,
@@ -330,12 +329,13 @@ def _get_mgr_concatenation_plan(mgr: BlockManager, indexers: dict[int, np.ndarra
330
329
)
331
330
)
332
331
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 )
338
335
336
+ # Assertions disabled for performance
337
+ # assert blk._mgr_locs.as_slice == placements.as_slice
338
+ # assert blk.shape[0] == shape[0]
339
339
unit = JoinUnit (blk , shape , join_unit_indexers )
340
340
341
341
plan .append ((placements , unit ))
@@ -349,6 +349,7 @@ def __init__(self, block: Block, shape: Shape, indexers=None):
349
349
# Note: block is None implies indexers is None, but not vice-versa
350
350
if indexers is None :
351
351
indexers = {}
352
+ # we should *never* have `0 in indexers`
352
353
self .block = block
353
354
self .indexers = indexers
354
355
self .shape = shape
@@ -599,20 +600,11 @@ def _trim_join_unit(join_unit: JoinUnit, length: int) -> JoinUnit:
599
600
600
601
Extra items that didn't fit are returned as a separate block.
601
602
"""
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
612
605
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 ))
616
608
617
609
extra_shape = (join_unit .shape [0 ] - length ,) + join_unit .shape [1 :]
618
610
join_unit .shape = (length ,) + join_unit .shape [1 :]
0 commit comments