@@ -340,33 +340,20 @@ def _verify_integrity(self):
340340 "tot_items: {1}" .format (len (self .items ), tot_items )
341341 )
342342
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 ):
352344 """
353- iterate over the blocks, collect and create a new block manager
345+ Iterate over the blocks, collect and create a new BlockManager.
354346
355347 Parameters
356348 ----------
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.
359351 filter : list, if supplied, only call the block if the filter is in
360352 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
365353
366354 Returns
367355 -------
368- Block Manager (new object)
369-
356+ BlockManager
370357 """
371358
372359 result_blocks = []
@@ -380,8 +367,7 @@ def apply(
380367 else :
381368 kwargs ["filter" ] = filter_locs
382369
383- if consolidate :
384- self ._consolidate_inplace ()
370+ self ._consolidate_inplace ()
385371
386372 if f == "where" :
387373 align_copy = True
@@ -429,11 +415,8 @@ def apply(
429415 result_blocks = _extend_blocks (applied , result_blocks )
430416
431417 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 )
437420 return bm
438421
439422 def quantile (
@@ -540,8 +523,8 @@ def get_axe(block, qs, axes):
540523 [make_block (values , ndim = 1 , placement = np .arange (len (values )))], axes [0 ]
541524 )
542525
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 )
545528
546529 def where (self , ** kwargs ):
547530 return self .apply ("where" , ** kwargs )
@@ -567,8 +550,8 @@ def fillna(self, **kwargs):
567550 def downcast (self , ** kwargs ):
568551 return self .apply ("downcast" , ** kwargs )
569552
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 )
572555
573556 def convert (self , ** kwargs ):
574557 return self .apply ("convert" , ** kwargs )
@@ -768,14 +751,19 @@ def copy(self, deep=True):
768751 """
769752 # this preserves the notion of view copying of axes
770753 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 ]
776762 else :
777763 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
779767
780768 def as_array (self , transpose = False , items = None ):
781769 """Convert the blockmanager data into an numpy array.
@@ -1527,10 +1515,6 @@ def get_slice(self, slobj, axis=0):
15271515 def index (self ):
15281516 return self .axes [0 ]
15291517
1530- def convert (self , ** kwargs ):
1531- """ convert the whole block as one """
1532- return self .apply ("convert" , ** kwargs )
1533-
15341518 @property
15351519 def dtype (self ):
15361520 return self ._block .dtype
0 commit comments