@@ -284,20 +284,26 @@ def _unpickle_sparse_frame_compat(self, state):
284
284
def to_dense (self ):
285
285
return SparseFrameAccessor (self ).to_dense ()
286
286
287
- def _apply_columns (self , func ):
287
+ def _apply_columns (self , func , * args , ** kwargs ):
288
288
"""
289
289
Get new SparseDataFrame applying func to each columns
290
290
"""
291
291
292
- new_data = {col : func (series )
292
+ new_data = {col : func (series , * args , ** kwargs )
293
293
for col , series in self .items ()}
294
294
295
295
return self ._constructor (
296
296
data = new_data , index = self .index , columns = self .columns ,
297
297
default_fill_value = self .default_fill_value ).__finalize__ (self )
298
298
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 )
301
307
302
308
def copy (self , deep = True ):
303
309
"""
0 commit comments