parameters: (blocks: tuple[Block, ...])
return_statement: return new_blocks
docstring: Merge blocks having same dtype, exclude non-consolidating blocks
docstring_summary: Merge blocks having same dtype, exclude non-consolidating blocks
docstring_tokens: Merge blocks having same dtype exclude non - consolidating blocks
function: def _consolidate(blocks: tuple[Block, ...]) -> list[Block]:
      """
      Merge blocks having same dtype, exclude non-consolidating blocks
      """
      # sort by _can_consolidate, dtype
      gkey = lambda x: x._consolidate_key
      grouper = itertools.groupby(sorted(blocks, key=gkey), gkey)
  
      new_blocks: list[Block] = []
      for (_can_consolidate, dtype), group_blocks in grouper:
          merged_blocks = _merge_blocks(
              list(group_blocks), dtype=dtype, can_consolidate=_can_consolidate
          )
          new_blocks = extend_blocks(merged_blocks, new_blocks)
      return new_blocks
function_tokens: def _consolidate ( blocks : tuple [ Block , ... ] ) -> list [ Block ] : # sort by _can_consolidate, dtype gkey = lambda x : x . _consolidate_key grouper = itertools . groupby ( sorted ( blocks , key = gkey ) , gkey ) new_blocks : list [ Block ] = [ ] for ( _can_consolidate , dtype ) , group_blocks in grouper : merged_blocks = _merge_blocks ( list ( group_blocks ) , dtype = dtype , can_consolidate = _can_consolidate ) new_blocks = extend_blocks ( merged_blocks , new_blocks ) return new_blocks