Merge blocks having same dtype, exclude non-consolidating blocks
(blocks: tuple[Block, ...])
| 2468 | |
| 2469 | |
| 2470 | def _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 | |
| 2487 | def _merge_blocks( |
no test coverage detected