Concatenate block managers into one. Parameters ---------- mgrs_indexers : list of (BlockManager, {axis: indexer,...}) tuples axes : list of Index concat_axis : int copy : bool Returns ------- BlockManager
(
mgrs_indexers, axes: list[Index], concat_axis: AxisInt, copy: bool
)
| 59 | |
| 60 | |
| 61 | def concatenate_managers( |
| 62 | mgrs_indexers, axes: list[Index], concat_axis: AxisInt, copy: bool |
| 63 | ) -> BlockManager: |
| 64 | """ |
| 65 | Concatenate block managers into one. |
| 66 | |
| 67 | Parameters |
| 68 | ---------- |
| 69 | mgrs_indexers : list of (BlockManager, {axis: indexer,...}) tuples |
| 70 | axes : list of Index |
| 71 | concat_axis : int |
| 72 | copy : bool |
| 73 | |
| 74 | Returns |
| 75 | ------- |
| 76 | BlockManager |
| 77 | """ |
| 78 | |
| 79 | needs_copy = copy and concat_axis == 0 |
| 80 | |
| 81 | # Assertions disabled for performance |
| 82 | # for tup in mgrs_indexers: |
| 83 | # # caller is responsible for ensuring this |
| 84 | # indexers = tup[1] |
| 85 | # assert concat_axis not in indexers |
| 86 | |
| 87 | if concat_axis == 0: |
| 88 | mgrs = _maybe_reindex_columns_na_proxy(axes, mgrs_indexers, needs_copy) |
| 89 | return mgrs[0].concat_horizontal(mgrs, axes) |
| 90 | |
| 91 | if len(mgrs_indexers) > 0 and mgrs_indexers[0][0].nblocks > 0: |
| 92 | first_dtype = mgrs_indexers[0][0].blocks[0].dtype |
| 93 | if first_dtype in [np.float64, np.float32]: |
| 94 | # TODO: support more dtypes here. This will be simpler once |
| 95 | # JoinUnit.is_na behavior is deprecated. |
| 96 | # (update 2024-04-13 that deprecation has been enforced) |
| 97 | if ( |
| 98 | all(_is_homogeneous_mgr(mgr, first_dtype) for mgr, _ in mgrs_indexers) |
| 99 | and len(mgrs_indexers) > 1 |
| 100 | ): |
| 101 | # Fastpath! |
| 102 | # Length restriction is just to avoid having to worry about 'copy' |
| 103 | shape = tuple(len(x) for x in axes) |
| 104 | nb = _concat_homogeneous_fastpath(mgrs_indexers, shape, first_dtype) |
| 105 | return BlockManager((nb,), axes) |
| 106 | |
| 107 | mgrs = _maybe_reindex_columns_na_proxy(axes, mgrs_indexers, needs_copy) |
| 108 | |
| 109 | if len(mgrs) == 1: |
| 110 | mgr = mgrs[0] |
| 111 | out = mgr.copy(deep=False) |
| 112 | out.axes = axes |
| 113 | return out |
| 114 | |
| 115 | blocks = [] |
| 116 | values: ArrayLike |
| 117 | |
| 118 | for placement, join_units in _get_combined_plan(mgrs): |
no test coverage detected