@@ -434,7 +434,7 @@ def f(m, v, i):
434
434
435
435
return self .split_and_operate (mask , f , inplace )
436
436
437
- def split_and_operate (self , mask , f , inplace ):
437
+ def split_and_operate (self , mask , f , inplace : bool ):
438
438
"""
439
439
split the block per-column, and apply the callable f
440
440
per-column, return a new block for each. Handle
@@ -493,17 +493,15 @@ def make_a_block(nv, ref_loc):
493
493
494
494
return new_blocks
495
495
496
- def _maybe_downcast (self , blocks , downcast = None ):
496
+ def _maybe_downcast (self , blocks : List [ "Block" ] , downcast = None ) -> List [ "Block" ] :
497
497
498
498
# no need to downcast our float
499
499
# unless indicated
500
- if downcast is None and self . is_float :
501
- return blocks
502
- elif downcast is None and ( self . is_timedelta or self . is_datetime ):
500
+ if downcast is None and (
501
+ self . is_float or self . is_timedelta or self . is_datetime
502
+ ):
503
503
return blocks
504
504
505
- if not isinstance (blocks , list ):
506
- blocks = [blocks ]
507
505
return _extend_blocks ([b .downcast (downcast ) for b in blocks ])
508
506
509
507
def downcast (self , dtypes = None ):
@@ -1343,7 +1341,15 @@ def shift(self, periods, axis=0, fill_value=None):
1343
1341
1344
1342
return [self .make_block (new_values )]
1345
1343
1346
- def where (self , other , cond , align = True , errors = "raise" , try_cast = False , axis = 0 ):
1344
+ def where (
1345
+ self ,
1346
+ other ,
1347
+ cond ,
1348
+ align = True ,
1349
+ errors = "raise" ,
1350
+ try_cast : bool = False ,
1351
+ axis : int = 0 ,
1352
+ ) -> List ["Block" ]:
1347
1353
"""
1348
1354
evaluate the block; return result block(s) from the result
1349
1355
@@ -1442,7 +1448,7 @@ def func(cond, values, other):
1442
1448
if try_cast :
1443
1449
result = self ._try_cast_result (result )
1444
1450
1445
- return self .make_block (result )
1451
+ return [ self .make_block (result )]
1446
1452
1447
1453
# might need to separate out blocks
1448
1454
axis = cond .ndim - 1
@@ -1474,9 +1480,9 @@ def _unstack(self, unstacker_func, new_columns, n_rows, fill_value):
1474
1480
new_columns : Index
1475
1481
All columns of the unstacked BlockManager.
1476
1482
n_rows : int
1477
- Only used in ExtensionBlock.unstack
1483
+ Only used in ExtensionBlock._unstack
1478
1484
fill_value : int
1479
- Only used in ExtensionBlock.unstack
1485
+ Only used in ExtensionBlock._unstack
1480
1486
1481
1487
Returns
1482
1488
-------
@@ -1550,7 +1556,7 @@ def quantile(self, qs, interpolation="linear", axis=0):
1550
1556
result = result [..., 0 ]
1551
1557
result = lib .item_from_zerodim (result )
1552
1558
1553
- ndim = getattr (result , "ndim" , None ) or 0
1559
+ ndim = np . ndim (result )
1554
1560
return make_block (result , placement = np .arange (len (result )), ndim = ndim )
1555
1561
1556
1562
def _replace_coerce (
@@ -1923,7 +1929,15 @@ def shift(
1923
1929
)
1924
1930
]
1925
1931
1926
- def where (self , other , cond , align = True , errors = "raise" , try_cast = False , axis = 0 ):
1932
+ def where (
1933
+ self ,
1934
+ other ,
1935
+ cond ,
1936
+ align = True ,
1937
+ errors = "raise" ,
1938
+ try_cast : bool = False ,
1939
+ axis : int = 0 ,
1940
+ ) -> List ["Block" ]:
1927
1941
if isinstance (other , ABCDataFrame ):
1928
1942
# ExtensionArrays are 1-D, so if we get here then
1929
1943
# `other` should be a DataFrame with a single column.
@@ -1968,7 +1982,7 @@ def where(self, other, cond, align=True, errors="raise", try_cast=False, axis=0)
1968
1982
np .where (cond , self .values , other ), dtype = dtype
1969
1983
)
1970
1984
1971
- return self .make_block_same_class (result , placement = self .mgr_locs )
1985
+ return [ self .make_block_same_class (result , placement = self .mgr_locs )]
1972
1986
1973
1987
@property
1974
1988
def _ftype (self ):
@@ -2706,7 +2720,7 @@ def f(m, v, i):
2706
2720
2707
2721
return blocks
2708
2722
2709
- def _maybe_downcast (self , blocks , downcast = None ):
2723
+ def _maybe_downcast (self , blocks : List [ "Block" ] , downcast = None ) -> List [ "Block" ] :
2710
2724
2711
2725
if downcast is not None :
2712
2726
return blocks
@@ -3031,7 +3045,15 @@ def concat_same_type(self, to_concat, placement=None):
3031
3045
values , placement = placement or slice (0 , len (values ), 1 ), ndim = self .ndim
3032
3046
)
3033
3047
3034
- def where (self , other , cond , align = True , errors = "raise" , try_cast = False , axis = 0 ):
3048
+ def where (
3049
+ self ,
3050
+ other ,
3051
+ cond ,
3052
+ align = True ,
3053
+ errors = "raise" ,
3054
+ try_cast : bool = False ,
3055
+ axis : int = 0 ,
3056
+ ) -> List ["Block" ]:
3035
3057
# TODO(CategoricalBlock.where):
3036
3058
# This can all be deleted in favor of ExtensionBlock.where once
3037
3059
# we enforce the deprecation.
0 commit comments