Skip to content

Commit ef0cf1e

Browse files
jbrockmendeljreback
authored andcommitted
REF: implement _split_op_result (pandas-dev#31027)
1 parent 586bcb1 commit ef0cf1e

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

pandas/core/internals/blocks.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -362,13 +362,17 @@ def delete(self, loc):
362362
self.values = np.delete(self.values, loc, 0)
363363
self.mgr_locs = self.mgr_locs.delete(loc)
364364

365-
def apply(self, func, **kwargs):
365+
def apply(self, func, **kwargs) -> List["Block"]:
366366
""" apply the function to my values; return a block if we are not
367367
one
368368
"""
369369
with np.errstate(all="ignore"):
370370
result = func(self.values, **kwargs)
371371

372+
return self._split_op_result(result)
373+
374+
def _split_op_result(self, result) -> List["Block"]:
375+
# See also: split_and_operate
372376
if is_extension_array_dtype(result) and result.ndim > 1:
373377
# if we get a 2D ExtensionArray, we need to split it into 1D pieces
374378
nbs = []
@@ -382,7 +386,7 @@ def apply(self, func, **kwargs):
382386
if not isinstance(result, Block):
383387
result = self.make_block(values=_block_shape(result, ndim=self.ndim))
384388

385-
return result
389+
return [result]
386390

387391
def fillna(self, value, limit=None, inplace=False, downcast=None):
388392
""" fillna on the block with the value. If we fail, then convert to

pandas/core/internals/managers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,7 @@ def _slice_take_blocks_ax0(self, slice_or_indexer, fill_tuple=None):
13411341
# only one item and each mgr loc is a copy of that single
13421342
# item.
13431343
for mgr_loc in mgr_locs:
1344-
newblk = blk.copy(deep=True)
1344+
newblk = blk.copy(deep=False)
13451345
newblk.mgr_locs = slice(mgr_loc, mgr_loc + 1)
13461346
blocks.append(newblk)
13471347

0 commit comments

Comments
 (0)