@@ -212,6 +212,8 @@ def concatenate_managers(
212
212
for placement , join_units in concat_plan :
213
213
unit = join_units [0 ]
214
214
blk = unit .block
215
+ # Assertion disabled for performance
216
+ # assert len(join_units) == len(mgrs_indexers)
215
217
216
218
if len (join_units ) == 1 :
217
219
values = blk .values
@@ -329,27 +331,20 @@ def _get_mgr_concatenation_plan(mgr: BlockManager):
329
331
plan : list of (BlockPlacement, JoinUnit) tuples
330
332
331
333
"""
332
- # Calculate post-reindex shape , save for item axis which will be separate
333
- # for each block anyway.
334
- mgr_shape_list = list (mgr .shape )
335
- mgr_shape = tuple (mgr_shape_list )
336
334
337
335
if mgr .is_single_block :
338
336
blk = mgr .blocks [0 ]
339
- return [(blk .mgr_locs , JoinUnit (blk , mgr_shape ))]
337
+ return [(blk .mgr_locs , JoinUnit (blk ))]
340
338
341
339
blknos = mgr .blknos
342
340
blklocs = mgr .blklocs
343
341
344
342
plan = []
345
343
for blkno , placements in libinternals .get_blkno_placements (blknos , group = False ):
346
344
347
- assert placements .is_slice_like
348
- assert blkno != - 1
349
-
350
- shape_list = list (mgr_shape )
351
- shape_list [0 ] = len (placements )
352
- shape = tuple (shape_list )
345
+ # Assertions disabled for performance; these should always hold
346
+ # assert placements.is_slice_like
347
+ # assert blkno != -1
353
348
354
349
blk = mgr .blocks [blkno ]
355
350
ax0_blk_indexer = blklocs [placements .indexer ]
@@ -379,19 +374,16 @@ def _get_mgr_concatenation_plan(mgr: BlockManager):
379
374
380
375
# Assertions disabled for performance
381
376
# assert blk._mgr_locs.as_slice == placements.as_slice
382
- # assert blk.shape[0] == shape[0]
383
- unit = JoinUnit (blk , shape )
377
+ unit = JoinUnit (blk )
384
378
385
379
plan .append ((placements , unit ))
386
380
387
381
return plan
388
382
389
383
390
384
class JoinUnit :
391
- def __init__ (self , block : Block , shape : Shape ):
392
- # Passing shape explicitly is required for cases when block is None.
385
+ def __init__ (self , block : Block ):
393
386
self .block = block
394
- self .shape = shape
395
387
396
388
def __repr__ (self ) -> str :
397
389
return f"{ type (self ).__name__ } ({ repr (self .block )} )"
@@ -404,22 +396,11 @@ def is_na(self) -> bool:
404
396
return False
405
397
406
398
def get_reindexed_values (self , empty_dtype : DtypeObj ) -> ArrayLike :
407
- values : ArrayLike
408
-
409
399
if self .is_na :
410
- return make_na_array (empty_dtype , self .shape )
400
+ return make_na_array (empty_dtype , self .block . shape )
411
401
412
402
else :
413
-
414
- if not self .block ._can_consolidate :
415
- # preserve these for validation in concat_compat
416
- return self .block .values
417
-
418
- # No dtype upcasting is done here, it will be performed during
419
- # concatenation itself.
420
- values = self .block .values
421
-
422
- return values
403
+ return self .block .values
423
404
424
405
425
406
def make_na_array (dtype : DtypeObj , shape : Shape ) -> ArrayLike :
@@ -558,6 +539,9 @@ def _is_uniform_join_units(join_units: list[JoinUnit]) -> bool:
558
539
first = join_units [0 ].block
559
540
if first .dtype .kind == "V" :
560
541
return False
542
+ elif len (join_units ) == 1 :
543
+ # only use this path when there is something to concatenate
544
+ return False
561
545
return (
562
546
# exclude cases where a) ju.block is None or b) we have e.g. Int64+int64
563
547
all (type (ju .block ) is type (first ) for ju in join_units )
@@ -570,13 +554,8 @@ def _is_uniform_join_units(join_units: list[JoinUnit]) -> bool:
570
554
or ju .block .dtype .kind in ["b" , "i" , "u" ]
571
555
for ju in join_units
572
556
)
573
- and
574
- # no blocks that would get missing values (can lead to type upcasts)
575
- # unless we're an extension dtype.
576
- all (not ju .is_na or ju .block .is_extension for ju in join_units )
577
- and
578
- # only use this path when there is something to concatenate
579
- len (join_units ) > 1
557
+ # this also precludes any blocks with dtype.kind == "V", since
558
+ # we excluded that case for `first` above.
580
559
)
581
560
582
561
@@ -598,10 +577,7 @@ def _trim_join_unit(join_unit: JoinUnit, length: int) -> JoinUnit:
598
577
extra_block = join_unit .block .getitem_block (slice (length , None ))
599
578
join_unit .block = join_unit .block .getitem_block (slice (length ))
600
579
601
- extra_shape = (join_unit .shape [0 ] - length ,) + join_unit .shape [1 :]
602
- join_unit .shape = (length ,) + join_unit .shape [1 :]
603
-
604
- return JoinUnit (block = extra_block , shape = extra_shape )
580
+ return JoinUnit (block = extra_block )
605
581
606
582
607
583
def _combine_concat_plans (plans ):
0 commit comments