@@ -372,8 +372,7 @@ def apply(self, func, **kwargs) -> list[Block]:
372
372
apply the function to my values; return a block if we are not
373
373
one
374
374
"""
375
- with np .errstate (all = "ignore" ):
376
- result = func (self .values , ** kwargs )
375
+ result = func (self .values , ** kwargs )
377
376
378
377
return self ._split_op_result (result )
379
378
@@ -399,9 +398,9 @@ def reduce(self, func, ignore_failures: bool = False) -> list[Block]:
399
398
return [nb ]
400
399
401
400
@final
402
- def _split_op_result (self , result ) -> list [Block ]:
401
+ def _split_op_result (self , result : ArrayLike ) -> list [Block ]:
403
402
# See also: split_and_operate
404
- if is_extension_array_dtype ( result ) and result .ndim > 1 :
403
+ if result .ndim > 1 and isinstance ( result . dtype , ExtensionDtype ) :
405
404
# TODO(EA2D): unnecessary with 2D EAs
406
405
# if we get a 2D ExtensionArray, we need to split it into 1D pieces
407
406
nbs = []
@@ -415,11 +414,9 @@ def _split_op_result(self, result) -> list[Block]:
415
414
nbs .append (block )
416
415
return nbs
417
416
418
- if not isinstance (result , Block ):
419
- result = maybe_coerce_values (result )
420
- result = self .make_block (result )
417
+ nb = self .make_block (result )
421
418
422
- return [result ]
419
+ return [nb ]
423
420
424
421
def fillna (
425
422
self , value , limit = None , inplace : bool = False , downcast = None
@@ -474,7 +471,8 @@ def _split(self) -> list[Block]:
474
471
for i , ref_loc in enumerate (self ._mgr_locs ):
475
472
vals = self .values [slice (i , i + 1 )]
476
473
477
- nb = self .make_block (vals , BlockPlacement (ref_loc ))
474
+ bp = BlockPlacement (ref_loc )
475
+ nb = type (self )(vals , placement = bp , ndim = 2 )
478
476
new_blocks .append (nb )
479
477
return new_blocks
480
478
@@ -647,7 +645,7 @@ def copy(self, deep: bool = True):
647
645
values = self .values
648
646
if deep :
649
647
values = values .copy ()
650
- return self . make_block_same_class (values )
648
+ return type ( self ) (values , placement = self . _mgr_locs , ndim = self . ndim )
651
649
652
650
# ---------------------------------------------------------------------
653
651
# Replace
@@ -1962,16 +1960,15 @@ def get_block_type(dtype: DtypeObj):
1962
1960
return cls
1963
1961
1964
1962
1965
- def new_block (values , placement , * , ndim : int , klass = None ) -> Block :
1963
+ def new_block (values , placement , * , ndim : int ) -> Block :
1966
1964
# caller is responsible for ensuring values is NOT a PandasArray
1967
1965
1968
1966
if not isinstance (placement , BlockPlacement ):
1969
1967
placement = BlockPlacement (placement )
1970
1968
1971
1969
check_ndim (values , placement , ndim )
1972
1970
1973
- if klass is None :
1974
- klass = get_block_type (values .dtype )
1971
+ klass = get_block_type (values .dtype )
1975
1972
1976
1973
values = maybe_coerce_values (values )
1977
1974
return klass (values , ndim = ndim , placement = placement )
0 commit comments