Skip to content

TYP: some typing in internals/concat.py #52581

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 2 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions pandas/_libs/internals.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class BlockPlacement:
def __iter__(self) -> Iterator[int]: ...
def __len__(self) -> int: ...
def delete(self, loc) -> BlockPlacement: ...
def add(self, other) -> BlockPlacement: ...
def append(self, others: list[BlockPlacement]) -> BlockPlacement: ...
def tile_for_unstack(self, factor: int) -> npt.NDArray[np.intp]: ...

Expand Down
15 changes: 10 additions & 5 deletions pandas/core/internals/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@
)

from pandas import Index
from pandas.core.internals.blocks import Block
from pandas.core.internals.blocks import (
Block,
BlockPlacement,
)


def _concatenate_array_managers(
Expand Down Expand Up @@ -262,10 +265,10 @@ def _concat_managers_axis0(
}
mgrs_indexers = _maybe_reindex_columns_na_proxy(axes, mgrs_indexers)

mgrs = [x[0] for x in mgrs_indexers]
mgrs: list[BlockManager] = [x[0] for x in mgrs_indexers]

offset = 0
blocks = []
blocks: list[Block] = []
for i, mgr in enumerate(mgrs):
# If we already reindexed, then we definitely don't need another copy
made_copy = had_reindexers[i]
Expand Down Expand Up @@ -317,7 +320,9 @@ def _maybe_reindex_columns_na_proxy(
return new_mgrs_indexers


def _get_mgr_concatenation_plan(mgr: BlockManager):
def _get_mgr_concatenation_plan(
mgr: BlockManager,
) -> list[tuple[BlockPlacement, JoinUnit]]:
"""
Construct concatenation plan for given block manager.

Expand All @@ -336,7 +341,7 @@ def _get_mgr_concatenation_plan(mgr: BlockManager):
blknos = mgr.blknos
blklocs = mgr.blklocs

plan = []
plan: list[tuple[BlockPlacement, JoinUnit]] = []
for blkno, placements in libinternals.get_blkno_placements(blknos, group=False):
assert placements.is_slice_like
assert blkno != -1
Expand Down