@@ -340,33 +340,20 @@ def _verify_integrity(self):
340
340
"tot_items: {1}" .format (len (self .items ), tot_items )
341
341
)
342
342
343
- def apply (
344
- self ,
345
- f ,
346
- axes = None ,
347
- filter = None ,
348
- do_integrity_check = False ,
349
- consolidate = True ,
350
- ** kwargs ,
351
- ):
343
+ def apply (self , f : str , filter = None , ** kwargs ):
352
344
"""
353
- iterate over the blocks, collect and create a new block manager
345
+ Iterate over the blocks, collect and create a new BlockManager.
354
346
355
347
Parameters
356
348
----------
357
- f : the callable or function name to operate on at the block level
358
- axes : optional (if not supplied, use self.axes)
349
+ f : str
350
+ Name of the Block method to apply.
359
351
filter : list, if supplied, only call the block if the filter is in
360
352
the block
361
- do_integrity_check : boolean, default False. Do the block manager
362
- integrity check
363
- consolidate: boolean, default True. Join together blocks having same
364
- dtype
365
353
366
354
Returns
367
355
-------
368
- Block Manager (new object)
369
-
356
+ BlockManager
370
357
"""
371
358
372
359
result_blocks = []
@@ -380,8 +367,7 @@ def apply(
380
367
else :
381
368
kwargs ["filter" ] = filter_locs
382
369
383
- if consolidate :
384
- self ._consolidate_inplace ()
370
+ self ._consolidate_inplace ()
385
371
386
372
if f == "where" :
387
373
align_copy = True
@@ -429,11 +415,8 @@ def apply(
429
415
result_blocks = _extend_blocks (applied , result_blocks )
430
416
431
417
if len (result_blocks ) == 0 :
432
- return self .make_empty (axes or self .axes )
433
- bm = type (self )(
434
- result_blocks , axes or self .axes , do_integrity_check = do_integrity_check
435
- )
436
- bm ._consolidate_inplace ()
418
+ return self .make_empty (self .axes )
419
+ bm = type (self )(result_blocks , self .axes , do_integrity_check = False )
437
420
return bm
438
421
439
422
def quantile (
@@ -540,8 +523,8 @@ def get_axe(block, qs, axes):
540
523
[make_block (values , ndim = 1 , placement = np .arange (len (values )))], axes [0 ]
541
524
)
542
525
543
- def isna (self , func , ** kwargs ):
544
- return self .apply ("apply" , func = func , ** kwargs )
526
+ def isna (self , func ):
527
+ return self .apply ("apply" , func = func )
545
528
546
529
def where (self , ** kwargs ):
547
530
return self .apply ("where" , ** kwargs )
@@ -567,8 +550,8 @@ def fillna(self, **kwargs):
567
550
def downcast (self , ** kwargs ):
568
551
return self .apply ("downcast" , ** kwargs )
569
552
570
- def astype (self , dtype , ** kwargs ):
571
- return self .apply ("astype" , dtype = dtype , ** kwargs )
553
+ def astype (self , dtype , copy : bool = False , errors : str = "raise" ):
554
+ return self .apply ("astype" , dtype = dtype , copy = copy , errors = errors )
572
555
573
556
def convert (self , ** kwargs ):
574
557
return self .apply ("convert" , ** kwargs )
@@ -768,14 +751,19 @@ def copy(self, deep=True):
768
751
"""
769
752
# this preserves the notion of view copying of axes
770
753
if deep :
771
- if deep == "all" :
772
- copy = lambda ax : ax .copy (deep = True )
773
- else :
774
- copy = lambda ax : ax .view ()
775
- new_axes = [copy (ax ) for ax in self .axes ]
754
+
755
+ def copy_func (ax ):
756
+ if deep == "all" :
757
+ return ax .copy (deep = True )
758
+ else :
759
+ return ax .view ()
760
+
761
+ new_axes = [copy_func (ax ) for ax in self .axes ]
776
762
else :
777
763
new_axes = list (self .axes )
778
- return self .apply ("copy" , axes = new_axes , deep = deep , do_integrity_check = False )
764
+ res = self .apply ("copy" , deep = deep )
765
+ res .axes = new_axes
766
+ return res
779
767
780
768
def as_array (self , transpose = False , items = None ):
781
769
"""Convert the blockmanager data into an numpy array.
@@ -1527,10 +1515,6 @@ def get_slice(self, slobj, axis=0):
1527
1515
def index (self ):
1528
1516
return self .axes [0 ]
1529
1517
1530
- def convert (self , ** kwargs ):
1531
- """ convert the whole block as one """
1532
- return self .apply ("convert" , ** kwargs )
1533
-
1534
1518
@property
1535
1519
def dtype (self ):
1536
1520
return self ._block .dtype
0 commit comments