Skip to content

CLN: internals.managers._form_blocks #52828

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
Apr 21, 2023
Merged
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
14 changes: 5 additions & 9 deletions pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2189,10 +2189,7 @@ def raise_construction_error(
# -----------------------------------------------------------------------


def _grouping_func(tup: tuple[int, ArrayLike]) -> tuple[int, bool, DtypeObj]:
# compat for numpy<1.21, in which comparing a np.dtype with an ExtensionDtype
# raises instead of returning False. Once earlier numpy versions are dropped,
# this can be simplified to `return tup[1].dtype`
def _grouping_func(tup: tuple[int, ArrayLike]) -> tuple[int, DtypeObj]:
dtype = tup[1].dtype

if is_1d_only_ea_dtype(dtype):
Expand All @@ -2202,15 +2199,14 @@ def _grouping_func(tup: tuple[int, ArrayLike]) -> tuple[int, bool, DtypeObj]:
else:
sep = 0

return sep, isinstance(dtype, np.dtype), dtype
return sep, dtype


def _form_blocks(arrays: list[ArrayLike], consolidate: bool, refs: list) -> list[Block]:
tuples = list(enumerate(arrays))

if not consolidate:
nbs = _tuples_to_blocks_no_consolidate(tuples, refs)
return nbs
return _tuples_to_blocks_no_consolidate(tuples, refs)

# when consolidating, we can ignore refs (either stacking always copies,
# or the EA is already copied in the calling dict_to_mgr)
Expand All @@ -2219,8 +2215,8 @@ def _form_blocks(arrays: list[ArrayLike], consolidate: bool, refs: list) -> list
# group by dtype
grouper = itertools.groupby(tuples, _grouping_func)

nbs = []
for (_, _, dtype), tup_block in grouper:
nbs: list[Block] = []
for (_, dtype), tup_block in grouper:
block_type = get_block_type(dtype)

if isinstance(dtype, np.dtype):
Expand Down