@@ -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" , skipna = True ):
5780
5780
"""
5781
5781
Cast a pandas object to a specified dtype ``dtype``.
5782
5782
@@ -5798,6 +5798,9 @@ def astype(self, dtype, copy=True, errors="raise"):
5798
5798
- ``ignore`` : suppress exceptions. On error return original object.
5799
5799
5800
5800
.. versionadded:: 0.20.0
5801
+ skipna : bool, default True
5802
+ Exclude NA/null values in type conversion.
5803
+
5801
5804
5802
5805
Returns
5803
5806
-------
@@ -5884,7 +5887,7 @@ def astype(self, dtype, copy=True, errors="raise"):
5884
5887
"the key in Series dtype mappings."
5885
5888
)
5886
5889
new_type = dtype [self .name ]
5887
- return self .astype (new_type , copy , errors )
5890
+ return self .astype (new_type , copy , errors , skipna )
5888
5891
5889
5892
for col_name in dtype .keys ():
5890
5893
if col_name not in self :
@@ -5896,7 +5899,12 @@ def astype(self, dtype, copy=True, errors="raise"):
5896
5899
for col_name , col in self .items ():
5897
5900
if col_name in dtype :
5898
5901
results .append (
5899
- col .astype (dtype = dtype [col_name ], copy = copy , errors = errors )
5902
+ col .astype (
5903
+ dtype = dtype [col_name ],
5904
+ copy = copy ,
5905
+ errors = errors ,
5906
+ skipna = skipna
5907
+ )
5900
5908
)
5901
5909
else :
5902
5910
results .append (results .append (col .copy () if copy else col ))
@@ -5911,7 +5919,9 @@ def astype(self, dtype, copy=True, errors="raise"):
5911
5919
5912
5920
else :
5913
5921
# else, only a single dtype is given
5914
- new_data = self ._data .astype (dtype = dtype , copy = copy , errors = errors )
5922
+ new_data = self ._data .astype (
5923
+ dtype = dtype , copy = copy , errors = errors , skipna = skipna
5924
+ )
5915
5925
return self ._constructor (new_data ).__finalize__ (self )
5916
5926
5917
5927
# GH 19920: retain column metadata after concat
0 commit comments