|
5 | 5 | from pandas._typing import ArrayLike
|
6 | 6 |
|
7 | 7 | if TYPE_CHECKING:
|
| 8 | + from pandas.core.internals.managers import BlockManager # noqa:F401 |
8 | 9 | from pandas.core.internals.blocks import Block # noqa:F401
|
9 | 10 |
|
10 | 11 |
|
11 |
| -def operate_blockwise(left, right, array_op): |
12 |
| - # At this point we have already checked |
13 |
| - # assert right._indexed_same(left) |
| 12 | +def operate_blockwise( |
| 13 | + left: "BlockManager", right: "BlockManager", array_op |
| 14 | +) -> "BlockManager": |
| 15 | + # At this point we have already checked the parent DataFrames for |
| 16 | + # assert rframe._indexed_same(lframe) |
14 | 17 |
|
15 | 18 | res_blks: List["Block"] = []
|
16 |
| - rmgr = right._mgr |
17 |
| - for n, blk in enumerate(left._mgr.blocks): |
| 19 | + for n, blk in enumerate(left.blocks): |
18 | 20 | locs = blk.mgr_locs
|
19 | 21 | blk_vals = blk.values
|
20 | 22 |
|
21 | 23 | left_ea = not isinstance(blk_vals, np.ndarray)
|
22 | 24 |
|
23 |
| - rblks = rmgr._slice_take_blocks_ax0(locs.indexer, only_slice=True) |
| 25 | + rblks = right._slice_take_blocks_ax0(locs.indexer, only_slice=True) |
24 | 26 |
|
25 | 27 | # Assertions are disabled for performance, but should hold:
|
26 | 28 | # if left_ea:
|
@@ -51,11 +53,11 @@ def operate_blockwise(left, right, array_op):
|
51 | 53 | # Assertions are disabled for performance, but should hold:
|
52 | 54 | # slocs = {y for nb in res_blks for y in nb.mgr_locs.as_array}
|
53 | 55 | # nlocs = sum(len(nb.mgr_locs.as_array) for nb in res_blks)
|
54 |
| - # assert nlocs == len(left.columns), (nlocs, len(left.columns)) |
| 56 | + # assert nlocs == len(left.items), (nlocs, len(left.items)) |
55 | 57 | # assert len(slocs) == nlocs, (len(slocs), nlocs)
|
56 | 58 | # assert slocs == set(range(nlocs)), slocs
|
57 | 59 |
|
58 |
| - new_mgr = type(rmgr)(res_blks, axes=rmgr.axes, do_integrity_check=False) |
| 60 | + new_mgr = type(right)(res_blks, axes=right.axes, do_integrity_check=False) |
59 | 61 | return new_mgr
|
60 | 62 |
|
61 | 63 |
|
|
0 commit comments