def _consolidate(blocks):
<EOL>gkey = lambda x: x._consolidate_key<EOL>grouper = itertools.groupby(sorted(blocks, key=gkey), gkey)<EOL>new_blocks = []<EOL>for (_can_consolidate, dtype), group_blocks in grouper:<EOL><INDENT>merged_blocks = _merge_blocks(list(group_blocks), dtype=dtype,<EOL>_can_consolidate=_can_consolidate)<EOL>new_blocks = _extend_blocks(merged_blocks, new_blocks)<EOL><DEDENT>return new_blocks<EOL>
Merge blocks having same dtype, exclude non-consolidating blocks