Skip to content

Commit cb59f2a

Browse files
committed
add back _from_blocks
1 parent 64abe4c commit cb59f2a

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

pandas/core/internals/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
BlockManager,
2020
SingleBlockManager,
2121
create_block_manager_from_arrays,
22+
create_block_manager_from_blocks,
2223
)
2324

2425
__all__ = [
@@ -38,6 +39,7 @@
3839
"concatenate_managers",
3940
# those two are preserved here for downstream compatibility (GH-33892)
4041
"create_block_manager_from_arrays",
42+
"create_block_manager_from_blocks",
4143
]
4244

4345

pandas/core/internals/managers.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,6 +1710,22 @@ def _equal_values(self: T, other: T) -> bool:
17101710
# Constructor Helpers
17111711

17121712

1713+
def create_block_manager_from_blocks(
1714+
blocks: list[Block], axes: list[Index], consolidate: bool = True
1715+
) -> BlockManager:
1716+
try:
1717+
mgr = BlockManager(blocks, axes)
1718+
1719+
except ValueError as err:
1720+
arrays = [blk.values for blk in blocks]
1721+
tot_items = sum(arr.shape[0] for arr in arrays)
1722+
raise construction_error(tot_items, arrays[0].shape[1:], axes, err)
1723+
1724+
if consolidate:
1725+
mgr._consolidate_inplace()
1726+
return mgr
1727+
1728+
17131729
# We define this here so we can override it in tests.extension.test_numpy
17141730
def _extract_array(obj):
17151731
return extract_array(obj, extract_numpy=True)

pandas/tests/internals/test_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def test_namespace():
4040
"SingleArrayManager",
4141
"concatenate_managers",
4242
"create_block_manager_from_arrays",
43-
"create_block_manager_from_array",
43+
"create_block_manager_from_blocks",
4444
]
4545

4646
result = [x for x in dir(internals) if not x.startswith("__")]

0 commit comments

Comments
 (0)