pd.Series([None, 42]).astype(str, skipna=True)
results in TypeError: astype() got an unexpected keyword argument 'skipna'
The provided snippet used to work before the 1.0 release. With the skipna argument, the None was preserved as a real np.nan type, instead of being converted to the string nan. The skipna argument seems to have gone in the 1.0 release and I can't find any way to restore this behavior without a custom function being passed to apply.
A series with [np.nan, '42']
pd.show_versions()commit : None
python : 3.8.1.final.0
python-bits : 64
OS : Linux
OS-release : 5.5.1-arch1-1
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : en_US.utf8
LOCALE : en_US.UTF-8
pandas : 1.0.0
numpy : 1.18.1
pytz : 2019.3
dateutil : 2.8.1
pip : 19.3
setuptools : 44.0.0
Cython : None
pytest : 5.3.5
hypothesis : None
sphinx : 2.2.1
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.4.2
html5lib : 1.0.1
pymysql : None
psycopg2 : 2.8.4 (dt dec pq3 ext lo64)
jinja2 : 2.11.1
IPython : 7.12.0
pandas_datareader: 0.8.1
bs4 : 4.8.2
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : 4.4.2
matplotlib : 3.1.3
numexpr : 2.7.1
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pytest : 5.3.5
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : 1.3.13
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
numba : None
Can confirm this used to work in 0.25.3, but no longer works now.
DataFrame.astype used to accept kwargs but they were removed in #28646
Thanks for opening the issue!
As I said on gitter, I was not aware of this keyword, which is not surprising as it has never been documented AFAIK (and also no tests clearly ..)
The reason it worked before (in certain cases) is because the kwargs were passed through to astype_nansafe, which has indeed a skipna keyword (https://github.com/pandas-dev/pandas/blob/935b6f46fa485f64bc534228618a417c87cd4766/pandas/core/dtypes/cast.py#L806)
this may have accidentally worked (passing skipna they)
but is not supported in any way
Actually, I found this only after reading some issues in this project. I can't exactly recall the source issue for my information on this argument, but the behavior was, for instance, also documented here: https://github.com/pandas-dev/pandas/issues/25353
In any case, is there an alternative proposal how to handle this case that is also working in 1.0?
this is not documented in #25353
this is a straight up bug with a PR but hasn鈥檛 been merged yet.
canonically something like
s[s.notna()] = s.astype(str)
would work
this is a duplicate issue
@languitar And you are certainly not alone in finding it from that issue .. (according to the :+1:'s)
In practice, it would be easy to restore this for 1.0.2. But in principle, I would personally prefer to not do this, since it was never actually documented (apart from the comment on that issue), only worked kind f accidentally, and is relatively easy to workaround until the actual issue is fixed.
However, depending on the discussion in https://github.com/pandas-dev/pandas/pull/28176, we might still want to add it back anyhow (if we would introduce such a keyword to handle the deprecation cycle). But, that will first need some discussion in #28176 then.
I don't think there's anything being done for 1.0.2 here. Pushing.
Any slick ways to handle this in versions > 1.0?
jrebacks solution seems the most straight forward s[s.notna()] = s.astype(str)
However, depending on the discussion in #28176, we might still want to add it back anyhow (_if_ we would introduce such a keyword to handle the deprecation cycle). But, that will first need some discussion in #28176 then.
makes sense, see https://github.com/pandas-dev/pandas/pull/28176#issuecomment-582895281, can we do this seperate to #28176 to resolve this regression.
Is there any update on this one? In pandas 1.0.5 it鈥檚 still complaining about unexpected keyword argument.
I think this may block the migration of some projects to 1.0.x.
@t0ma-sz #28176 was closed as stale.
if you would like to submit a PR and address https://github.com/pandas-dev/pandas/pull/28176#issuecomment-605620662, we can review again.