@@ -5776,7 +5776,7 @@ def _to_dict_of_blocks(self, copy=True):
5776
5776
for k , v , in self ._data .to_dict (copy = copy ).items ()
5777
5777
}
5778
5778
5779
- def astype (self , dtype , copy = True , errors = "raise" ):
5779
+ def astype (self , dtype , copy = True , errors = "raise" , ** kwargs ):
5780
5780
"""
5781
5781
Cast a pandas object to a specified dtype ``dtype``.
5782
5782
@@ -5799,6 +5799,8 @@ def astype(self, dtype, copy=True, errors="raise"):
5799
5799
5800
5800
.. versionadded:: 0.20.0
5801
5801
5802
+ **kwargs : keyword arguments to pass on to the constructor
5803
+
5802
5804
Returns
5803
5805
-------
5804
5806
casted : same type as caller
@@ -5884,7 +5886,7 @@ def astype(self, dtype, copy=True, errors="raise"):
5884
5886
"the key in Series dtype mappings."
5885
5887
)
5886
5888
new_type = dtype [self .name ]
5887
- return self .astype (new_type , copy , errors )
5889
+ return self .astype (new_type , copy , errors , ** kwargs )
5888
5890
5889
5891
for col_name in dtype .keys ():
5890
5892
if col_name not in self :
@@ -5896,7 +5898,9 @@ def astype(self, dtype, copy=True, errors="raise"):
5896
5898
for col_name , col in self .items ():
5897
5899
if col_name in dtype :
5898
5900
results .append (
5899
- col .astype (dtype = dtype [col_name ], copy = copy , errors = errors )
5901
+ col .astype (
5902
+ dtype = dtype [col_name ], copy = copy , errors = errors , ** kwargs
5903
+ )
5900
5904
)
5901
5905
else :
5902
5906
results .append (results .append (col .copy () if copy else col ))
@@ -5911,7 +5915,9 @@ def astype(self, dtype, copy=True, errors="raise"):
5911
5915
5912
5916
else :
5913
5917
# else, only a single dtype is given
5914
- new_data = self ._data .astype (dtype = dtype , copy = copy , errors = errors )
5918
+ new_data = self ._data .astype (
5919
+ dtype = dtype , copy = copy , errors = errors , ** kwargs
5920
+ )
5915
5921
return self ._constructor (new_data ).__finalize__ (self )
5916
5922
5917
5923
# GH 19920: retain column metadata after concat
0 commit comments