Skip to content

Commit 2cb2d1e

Browse files
topper-123Yi Wei
authored and
Yi Wei
committed
CLN: internals.managers._form_blocks (pandas-dev#52828)
CLN: managers._form_blocks
1 parent 2379146 commit 2cb2d1e

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

pandas/core/internals/managers.py

+5-9
Original file line numberDiff line numberDiff line change
@@ -2189,10 +2189,7 @@ def raise_construction_error(
21892189
# -----------------------------------------------------------------------
21902190

21912191

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

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

2205-
return sep, isinstance(dtype, np.dtype), dtype
2202+
return sep, dtype
22062203

22072204

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

22112208
if not consolidate:
2212-
nbs = _tuples_to_blocks_no_consolidate(tuples, refs)
2213-
return nbs
2209+
return _tuples_to_blocks_no_consolidate(tuples, refs)
22142210

22152211
# when consolidating, we can ignore refs (either stacking always copies,
22162212
# 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
22192215
# group by dtype
22202216
grouper = itertools.groupby(tuples, _grouping_func)
22212217

2222-
nbs = []
2223-
for (_, _, dtype), tup_block in grouper:
2218+
nbs: list[Block] = []
2219+
for (_, dtype), tup_block in grouper:
22242220
block_type = get_block_type(dtype)
22252221

22262222
if isinstance(dtype, np.dtype):

0 commit comments

Comments
 (0)