@@ -284,20 +284,26 @@ def _unpickle_sparse_frame_compat(self, state):
284284 def to_dense (self ):
285285 return SparseFrameAccessor (self ).to_dense ()
286286
287- def _apply_columns (self , func ):
287+ def _apply_columns (self , func , * args , ** kwargs ):
288288 """
289289 Get new SparseDataFrame applying func to each columns
290290 """
291291
292- new_data = {col : func (series )
292+ new_data = {col : func (series , * args , ** kwargs )
293293 for col , series in self .items ()}
294294
295295 return self ._constructor (
296296 data = new_data , index = self .index , columns = self .columns ,
297297 default_fill_value = self .default_fill_value ).__finalize__ (self )
298298
299- def astype (self , dtype ):
300- return self ._apply_columns (lambda x : x .astype (dtype ))
299+ def astype (self , dtype , ** kwargs ):
300+
301+ def f (x , dtype , ** kwargs ):
302+ if isinstance (dtype , (dict , Series )):
303+ dtype = dtype [x .name ]
304+ return x .astype (dtype , ** kwargs )
305+
306+ return self ._apply_columns (f , dtype = dtype , ** kwargs )
301307
302308 def copy (self , deep = True ):
303309 """
0 commit comments