@@ -1859,12 +1859,20 @@ def construction_error(
1859
1859
# -----------------------------------------------------------------------
1860
1860
1861
1861
1862
- def _grouping_func (tup : tuple [int , ArrayLike ]) -> tuple [bool , DtypeObj ]:
1862
+ def _grouping_func (tup : tuple [int , ArrayLike ]) -> tuple [int , bool , DtypeObj ]:
1863
1863
# compat for numpy<1.21, in which comparing a np.dtype with an ExtensionDtype
1864
1864
# raises instead of returning False. Once earlier numpy versions are dropped,
1865
1865
# this can be simplified to `return tup[1].dtype`
1866
1866
dtype = tup [1 ].dtype
1867
- return isinstance (dtype , np .dtype ), dtype
1867
+
1868
+ if is_1d_only_ea_dtype (dtype ):
1869
+ # We know these won't be consolidated, so don't need to group these.
1870
+ # This avoids expensive comparisons of CategoricalDtype objects
1871
+ sep = id (dtype )
1872
+ else :
1873
+ sep = 0
1874
+
1875
+ return sep , isinstance (dtype , np .dtype ), dtype
1868
1876
1869
1877
1870
1878
def _form_blocks (arrays : list [ArrayLike ], consolidate : bool ) -> list [Block ]:
@@ -1878,7 +1886,7 @@ def _form_blocks(arrays: list[ArrayLike], consolidate: bool) -> list[Block]:
1878
1886
grouper = itertools .groupby (tuples , _grouping_func )
1879
1887
1880
1888
nbs = []
1881
- for (_ , dtype ), tup_block in grouper :
1889
+ for (_ , _ , dtype ), tup_block in grouper :
1882
1890
block_type = get_block_type (None , dtype )
1883
1891
1884
1892
if isinstance (dtype , np .dtype ):
0 commit comments