From c4e37a1a1a4e3508c6e96700f9334e57ba1dec44 Mon Sep 17 00:00:00 2001 From: Terji Petersen Date: Fri, 21 Apr 2023 15:37:58 +0100 Subject: [PATCH] CLN: managers._form_blocks --- pandas/core/internals/managers.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/pandas/core/internals/managers.py b/pandas/core/internals/managers.py index ff637695a4816..7c02781b16456 100644 --- a/pandas/core/internals/managers.py +++ b/pandas/core/internals/managers.py @@ -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): @@ -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) @@ -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):