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

Function concatenate_managers

pandas/core/internals/concat.py:61–155  ·  view source on GitHub ↗

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
)

Source from the content-addressed store, hash-verified

59
60
61def 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):

Callers 1

_get_resultFunction · 0.90

Calls 15

BlockManagerClass · 0.90
is_1d_only_ea_dtypeFunction · 0.90
concat_compatFunction · 0.90
ensure_block_shapeFunction · 0.90
new_block_2dFunction · 0.90
_is_homogeneous_mgrFunction · 0.85
_get_combined_planFunction · 0.85
_is_uniform_join_unitsFunction · 0.85
_concatenate_join_unitsFunction · 0.85

Tested by

no test coverage detected