@@ -510,54 +510,24 @@ def _maybe_downcast(self, blocks: list[Block], downcast=None) -> list[Block]:
510
510
[blk .convert (datetime = True , numeric = False ) for blk in blocks ]
511
511
)
512
512
513
- # no need to downcast our float
514
- # unless indicated
515
- if downcast is None and self . dtype . kind in [ "f" , "c" , "m" , "M" ] :
516
- # passing "infer" to maybe_downcast_to_dtype (via self.downcast)
517
- # would be a no-op, so we can short-circuit
513
+ if downcast is None :
514
+ return blocks
515
+ if downcast is False :
516
+ # turn if off completely
517
+ # TODO: not reached, deprecate in favor of downcast=None
518
518
return blocks
519
519
520
- return extend_blocks ([b .downcast (downcast ) for b in blocks ])
520
+ return extend_blocks ([b ._downcast_2d (downcast ) for b in blocks ])
521
521
522
522
@final
523
- def downcast (self , dtypes = None ) -> list [Block ]:
524
- """try to downcast each item to the dict of dtypes if present"""
525
- # turn it off completely
526
- if dtypes is False :
527
- return [self ]
528
-
529
- values = self .values
530
-
531
- if self .ndim == 1 :
532
-
533
- # try to cast all non-floats here
534
- if dtypes is None :
535
- dtypes = "infer"
536
-
537
- nv = maybe_downcast_to_dtype (values , dtypes )
538
- return [self .make_block (nv )]
539
-
540
- # ndim > 1
541
- if dtypes is None :
542
- return [self ]
543
-
544
- if not (dtypes == "infer" or isinstance (dtypes , dict )):
545
- raise ValueError (
546
- "downcast must have a dictionary or 'infer' as its argument"
547
- )
548
- elif dtypes != "infer" :
549
- raise AssertionError ("dtypes as dict is not supported yet" )
550
-
551
- return self ._downcast_2d ()
552
-
553
523
@maybe_split
554
- def _downcast_2d (self ) -> list [Block ]:
524
+ def _downcast_2d (self , dtype ) -> list [Block ]:
555
525
"""
556
526
downcast specialized to 2D case post-validation.
557
527
558
528
Refactored to allow use of maybe_split.
559
529
"""
560
- new_values = maybe_downcast_to_dtype (self .values , dtype = "infer" )
530
+ new_values = maybe_downcast_to_dtype (self .values , dtype = dtype )
561
531
return [self .make_block (new_values )]
562
532
563
533
@final
@@ -1098,8 +1068,8 @@ def interpolate(
1098
1068
** kwargs ,
1099
1069
)
1100
1070
1101
- nbs = [ self .make_block_same_class (interp_values )]
1102
- return self ._maybe_downcast (nbs , downcast )
1071
+ nb = self .make_block_same_class (interp_values )
1072
+ return nb ._maybe_downcast ([ nb ] , downcast )
1103
1073
1104
1074
def take_nd (
1105
1075
self ,
0 commit comments