Skip to content

BUG: astype transforms NA to "NA" #61141

Open
@latot

Description

@latot

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas

a = pandas.Series([pandas.NA], dtype = "str")

# This is tight
print(type(a[0]))
<class 'pandas._libs.missing.NAType'>

print(type(a.astype("str")[0]))
<class 'str'>

Issue Description

When we work with missing data, and we do transformation from NA to "str", is does not keep the NA value, instead returns the string "NA".

Expected Behavior

Return NA instead of "NA"

Installed Versions

INSTALLED VERSIONS

commit : 0691c5c
python : 3.12.9
python-bits : 64
OS : Linux
OS-release : 6.12.16-gentoo-x86_64
Version : #1 SMP PREEMPT_DYNAMIC Tue Feb 25 08:36:23 -03 2025
machine : x86_64
processor : AMD Ryzen 7 5800H with Radeon Graphics
byteorder : little
LC_ALL : None
LANG : es_CL.utf8
LOCALE : es_CL.UTF-8

pandas : 2.2.3
numpy : 2.2.3
pytz : 2025.1
dateutil : 2.9.0.post0
pip : 25.0.1
Cython : None
sphinx : None
IPython : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
blosc : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : None
lxml.etree : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
psycopg2 : None
pymysql : None
pyarrow : None
pyreadstat : None
pytest : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
tzdata : 2025.1
qtpy : None
pyqt5 : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNeeds TriageIssue that has not been reviewed by a pandas team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions