Skip to content

PERF: DataFrame(ndarray) #43307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pandas/core/internals/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,9 @@ def ndarray_to_mgr(
if len(columns) == 0:
block_values = []

return create_block_manager_from_blocks(block_values, [columns, index])
return create_block_manager_from_blocks(
block_values, [columns, index], verify_integrity=False
)


def _check_values_indices_shape_match(
Expand Down
19 changes: 17 additions & 2 deletions pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1553,6 +1553,11 @@ def is_consolidated(self) -> bool:
return self._is_consolidated

def _consolidate_check(self) -> None:
if len(self.blocks) == 1:
# fastpath
self._is_consolidated = True
self._known_consolidated = True
return
dtypes = [blk.dtype for blk in self.blocks if blk._can_consolidate]
self._is_consolidated = len(dtypes) == len(set(dtypes))
self._known_consolidated = True
Expand Down Expand Up @@ -1775,10 +1780,20 @@ def _equal_values(self: T, other: T) -> bool:


def create_block_manager_from_blocks(
blocks: list[Block], axes: list[Index], consolidate: bool = True
blocks: list[Block],
axes: list[Index],
consolidate: bool = True,
verify_integrity: bool = True,
) -> BlockManager:
# If verify_integrity=False, then caller is responsible for checking
# all(x.shape[-1] == len(axes[1]) for x in blocks)
# sum(x.shape[0] for x in blocks) == len(axes[0])
# set(x for for blk in blocks for x in blk.mgr_locs) == set(range(len(axes[0])))
# all(blk.ndim == 2 for blk in blocks)
# This allows us to safely pass verify_integrity=False

try:
mgr = BlockManager(blocks, axes)
mgr = BlockManager(blocks, axes, verify_integrity=verify_integrity)

except ValueError as err:
arrays = [blk.values for blk in blocks]
Expand Down