Skip to content

REF: avoid having 0 in JoinUnit.indexers #43592

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 11 additions & 19 deletions pandas/core/internals/concat.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import copy
import itertools
from typing import (
TYPE_CHECKING,
Expand Down Expand Up @@ -330,12 +329,13 @@ def _get_mgr_concatenation_plan(mgr: BlockManager, indexers: dict[int, np.ndarra
)
)

# Omit indexer if no item reindexing is required.
if unit_no_ax0_reindexing:
join_unit_indexers.pop(0, None)
else:
join_unit_indexers[0] = ax0_blk_indexer
if not unit_no_ax0_reindexing:
# create block from subset of columns
blk = blk.getitem_block(ax0_blk_indexer)

# Assertions disabled for performance
# assert blk._mgr_locs.as_slice == placements.as_slice
# assert blk.shape[0] == shape[0]
unit = JoinUnit(blk, shape, join_unit_indexers)

plan.append((placements, unit))
Expand All @@ -349,6 +349,7 @@ def __init__(self, block: Block, shape: Shape, indexers=None):
# Note: block is None implies indexers is None, but not vice-versa
if indexers is None:
indexers = {}
# we should *never* have `0 in indexers`
self.block = block
self.indexers = indexers
self.shape = shape
Expand Down Expand Up @@ -599,20 +600,11 @@ def _trim_join_unit(join_unit: JoinUnit, length: int) -> JoinUnit:

Extra items that didn't fit are returned as a separate block.
"""
if 0 not in join_unit.indexers:
extra_indexers = join_unit.indexers

if join_unit.block is None:
extra_block = None
else:
extra_block = join_unit.block.getitem_block(slice(length, None))
join_unit.block = join_unit.block.getitem_block(slice(length))
else:
extra_block = join_unit.block
assert 0 not in join_unit.indexers
extra_indexers = join_unit.indexers

extra_indexers = copy.copy(join_unit.indexers)
extra_indexers[0] = extra_indexers[0][length:]
join_unit.indexers[0] = join_unit.indexers[0][:length]
extra_block = join_unit.block.getitem_block(slice(length, None))
join_unit.block = join_unit.block.getitem_block(slice(length))

extra_shape = (join_unit.shape[0] - length,) + join_unit.shape[1:]
join_unit.shape = (length,) + join_unit.shape[1:]
Expand Down