Skip to content

pandas.DataFrame.astype casts numerical nulls to string 'nan' #28186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
shubhambmehta opened this issue Aug 28, 2019 · 1 comment
Closed

pandas.DataFrame.astype casts numerical nulls to string 'nan' #28186

shubhambmehta opened this issue Aug 28, 2019 · 1 comment
Labels
Duplicate Report Duplicate issue or pull request

Comments

@shubhambmehta
Copy link

import pandas as pd
import numpy as np

s = pd.Series([1, 2, np.nan])
print str(s.isnull().any())

s = s.astype(str)
print str(s.isnull().any())

##output
True 
False

Problem description

When casting a series from float to string, the nulls in float should also be nulls in string. But, astype method converts the nulls to string 'nan', and so it does not reflect as null.

Expected Output

True
True

Output of pd.show_versions()

[paste the output of pd.show_versions() here below this line]
INSTALLED VERSIONS

commit: None
python: 2.7.12.final.0
python-bits: 64
OS: Linux
OS-release: 4.4.0-154-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_IN
LOCALE: None.None

pandas: 0.24.1
pytest: 2.8.7
pip: 19.0.1
setuptools: 40.6.2
Cython: None
numpy: 1.16.1
scipy: 1.1.0
pyarrow: None
xarray: None
IPython: 5.5.0
sphinx: None
patsy: 0.5.1
dateutil: 2.7.5
pytz: 2018.9
blosc: None
bottleneck: None
tables: 3.2.2
numexpr: 2.4.3
feather: None
matplotlib: 1.5.1
openpyxl: 2.3.0
xlrd: 0.9.4
xlwt: 0.7.5
xlsxwriter: None
lxml.etree: 3.5.0
bs4: 4.4.1
html5lib: 0.999
sqlalchemy: None
pymysql: None
psycopg2: 2.7.3.2 (dt dec pq3 ext lo64)
jinja2: 2.8
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None

@WillAyd
Copy link
Member

WillAyd commented Aug 28, 2019

Thanks for the report but this is a duplicate of #25353 - let's keep any discussion therein

@WillAyd WillAyd added the Duplicate Report Duplicate issue or pull request label Aug 28, 2019
@WillAyd WillAyd closed this as completed Aug 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request
Projects
None yet
Development

No branches or pull requests

2 participants