MCPcopy
hub / github.com/pandas-dev/pandas / _consolidate

Function _consolidate

pandas/core/internals/managers.py:2470–2484  ·  view source on GitHub ↗

Merge blocks having same dtype, exclude non-consolidating blocks

(blocks: tuple[Block, ...])

Source from the content-addressed store, hash-verified

2468
2469
2470def _consolidate(blocks: tuple[Block, ...]) -> tuple[Block, ...]:
2471 """
2472 Merge blocks having same dtype, exclude non-consolidating blocks
2473 """
2474 # sort by _can_consolidate, dtype
2475 gkey = lambda x: x._consolidate_key
2476 grouper = itertools.groupby(sorted(blocks, key=gkey), gkey)
2477
2478 new_blocks: list[Block] = []
2479 for (_can_consolidate, dtype), group_blocks in grouper:
2480 merged_blocks, _ = _merge_blocks(
2481 list(group_blocks), dtype=dtype, can_consolidate=_can_consolidate
2482 )
2483 new_blocks = extend_blocks(merged_blocks, new_blocks)
2484 return tuple(new_blocks)
2485
2486
2487def _merge_blocks(

Callers 1

_consolidate_inplaceMethod · 0.85

Calls 3

extend_blocksFunction · 0.90
_merge_blocksFunction · 0.85
groupbyMethod · 0.45

Tested by

no test coverage detected