|
24 | 24 | Tuple,
|
25 | 25 | Type,
|
26 | 26 | Union,
|
27 |
| - cast, |
28 | 27 | )
|
29 | 28 | import warnings
|
30 | 29 |
|
@@ -1100,24 +1099,19 @@ def blk_func(block: "Block") -> List["Block"]:
|
1100 | 1099 | # continue and exclude the block
|
1101 | 1100 | raise
|
1102 | 1101 | else:
|
1103 |
| - result = cast(DataFrame, result) |
| 1102 | + assert isinstance(result, (Series, DataFrame)) # for mypy |
| 1103 | + # In the case of object dtype block, it may have been split |
| 1104 | + # in the operation. We un-split here. |
| 1105 | + result = result._consolidate() |
| 1106 | + assert isinstance(result, (Series, DataFrame)) # for mypy |
| 1107 | + assert len(result._mgr.blocks) == 1 |
| 1108 | + |
1104 | 1109 | # unwrap DataFrame to get array
|
1105 |
| - if len(result._mgr.blocks) != 1: |
1106 |
| - # We've split an object block! Everything we've assumed |
1107 |
| - # about a single block input returning a single block output |
1108 |
| - # is a lie. To keep the code-path for the typical non-split case |
1109 |
| - # clean, we choose to clean up this mess later on. |
1110 |
| - assert len(locs) == result.shape[1] |
1111 |
| - for i, loc in enumerate(locs): |
1112 |
| - agg_block = result.iloc[:, [i]]._mgr.blocks[0] |
1113 |
| - agg_block.mgr_locs = [loc] |
1114 |
| - new_blocks.append(agg_block) |
1115 |
| - else: |
1116 |
| - result = result._mgr.blocks[0].values |
1117 |
| - if isinstance(result, np.ndarray) and result.ndim == 1: |
1118 |
| - result = result.reshape(1, -1) |
1119 |
| - agg_block = cast_result_block(result, block, how) |
1120 |
| - new_blocks = [agg_block] |
| 1110 | + result = result._mgr.blocks[0].values |
| 1111 | + if isinstance(result, np.ndarray) and result.ndim == 1: |
| 1112 | + result = result.reshape(1, -1) |
| 1113 | + agg_block = cast_result_block(result, block, how) |
| 1114 | + new_blocks = [agg_block] |
1121 | 1115 | else:
|
1122 | 1116 | agg_block = cast_result_block(result, block, how)
|
1123 | 1117 | new_blocks = [agg_block]
|
|
0 commit comments