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

Method _init_mgr

pandas/core/generic.py:265–292  ·  view source on GitHub ↗

passed a manager and a axes dict

(
        cls,
        mgr: Manager,
        axes: dict[Literal["index", "columns"], Axes | None],
        dtype: DtypeObj | None = None,
        copy: bool = False,
    )

Source from the content-addressed store, hash-verified

263 @final
264 @classmethod
265 def _init_mgr(
266 cls,
267 mgr: Manager,
268 axes: dict[Literal["index", "columns"], Axes | None],
269 dtype: DtypeObj | None = None,
270 copy: bool = False,
271 ) -> Manager:
272 """passed a manager and a axes dict"""
273 for a, axe in axes.items():
274 if axe is not None:
275 axe = ensure_index(axe)
276 bm_axis = cls._get_block_manager_axis(a)
277 mgr = mgr.reindex_axis(axe, axis=bm_axis)
278
279 # make a copy if explicitly requested
280 if copy:
281 mgr = mgr.copy(deep=True)
282 if dtype is not None:
283 # avoid further copies if we can
284 if (
285 isinstance(mgr, BlockManager)
286 and len(mgr.blocks) == 1
287 and mgr.blocks[0].values.dtype == dtype
288 ):
289 pass
290 else:
291 mgr = mgr.astype(dtype=dtype)
292 return mgr
293
294 @final
295 @classmethod

Callers 1

__init__Method · 0.80

Calls 6

ensure_indexFunction · 0.85
reindex_axisMethod · 0.80
itemsMethod · 0.45
copyMethod · 0.45
astypeMethod · 0.45

Tested by

no test coverage detected