@@ -491,11 +491,11 @@ def _maybe_downcast(self, blocks: List["Block"], downcast=None) -> List["Block"]
491
491
492
492
return extend_blocks ([b .downcast (downcast ) for b in blocks ])
493
493
494
- def downcast (self , dtypes = None ):
494
+ def downcast (self , dtypes = None ) -> List [ "Block" ] :
495
495
""" try to downcast each item to the dict of dtypes if present """
496
496
# turn it off completely
497
497
if dtypes is False :
498
- return self
498
+ return [ self ]
499
499
500
500
values = self .values
501
501
@@ -506,11 +506,11 @@ def downcast(self, dtypes=None):
506
506
dtypes = "infer"
507
507
508
508
nv = maybe_downcast_to_dtype (values , dtypes )
509
- return self .make_block (nv )
509
+ return [ self .make_block (nv )]
510
510
511
511
# ndim > 1
512
512
if dtypes is None :
513
- return self
513
+ return [ self ]
514
514
515
515
if not (dtypes == "infer" or isinstance (dtypes , dict )):
516
516
raise ValueError (
@@ -639,13 +639,13 @@ def convert(
639
639
numeric : bool = True ,
640
640
timedelta : bool = True ,
641
641
coerce : bool = False ,
642
- ):
642
+ ) -> List [ "Block" ] :
643
643
"""
644
644
attempt to coerce any object types to better types return a copy
645
645
of the block (if copy = True) by definition we are not an ObjectBlock
646
646
here!
647
647
"""
648
- return self .copy () if copy else self
648
+ return [ self .copy ()] if copy else [ self ]
649
649
650
650
def _can_hold_element (self , element : Any ) -> bool :
651
651
""" require the same dtype as ourselves """
@@ -788,7 +788,9 @@ def replace(
788
788
convert = convert ,
789
789
)
790
790
if convert :
791
- blocks = [b .convert (numeric = False , copy = not inplace ) for b in blocks ]
791
+ blocks = extend_blocks (
792
+ [b .convert (numeric = False , copy = not inplace ) for b in blocks ]
793
+ )
792
794
return blocks
793
795
794
796
def _replace_single (self , * args , ** kwargs ):
@@ -2461,12 +2463,10 @@ def convert(
2461
2463
numeric : bool = True ,
2462
2464
timedelta : bool = True ,
2463
2465
coerce : bool = False ,
2464
- ):
2466
+ ) -> List [ "Block" ] :
2465
2467
"""
2466
2468
attempt to coerce any object types to better types return a copy of
2467
2469
the block (if copy = True) by definition we ARE an ObjectBlock!!!!!
2468
-
2469
- can return multiple blocks!
2470
2470
"""
2471
2471
# operate column-by-column
2472
2472
def f (mask , val , idx ):
@@ -2639,8 +2639,10 @@ def re_replacer(s):
2639
2639
# convert
2640
2640
block = self .make_block (new_values )
2641
2641
if convert :
2642
- block = block .convert (numeric = False )
2643
- return block
2642
+ nbs = block .convert (numeric = False )
2643
+ else :
2644
+ nbs = [block ]
2645
+ return nbs
2644
2646
2645
2647
def _replace_coerce (
2646
2648
self , to_replace , value , inplace = True , regex = False , convert = False , mask = None
@@ -2669,7 +2671,7 @@ def _replace_coerce(
2669
2671
A new block if there is anything to replace or the original block.
2670
2672
"""
2671
2673
if mask .any ():
2672
- block = super ()._replace_coerce (
2674
+ nbs = super ()._replace_coerce (
2673
2675
to_replace = to_replace ,
2674
2676
value = value ,
2675
2677
inplace = inplace ,
@@ -2678,11 +2680,11 @@ def _replace_coerce(
2678
2680
mask = mask ,
2679
2681
)
2680
2682
if convert :
2681
- block = [b .convert (numeric = False , copy = True ) for b in block ]
2682
- return block
2683
+ nbs = extend_blocks ( [b .convert (numeric = False , copy = True ) for b in nbs ])
2684
+ return nbs
2683
2685
if convert :
2684
- return [ self .convert (numeric = False , copy = True )]
2685
- return self
2686
+ return self .convert (numeric = False , copy = True )
2687
+ return [ self ]
2686
2688
2687
2689
2688
2690
class CategoricalBlock (ExtensionBlock ):
0 commit comments