BUG: 'assign' on empty DataFrame with dtype=string column gives "ValueError: StringArray requires a sequence of strings or pandas.NA" #43119
Labels
Bug
Missing-data
np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Strings
String extension data type and string data
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
(optional) I have confirmed this bug exists on the master branch of pandas.
Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
Code Sample, a copy-pastable example
Full traceback:
Problem description
The
broken
code doesn't seem meaningfully different to the working versions, but throws an exception; from a very quick look (and as hinted by theworking2
output), it looks like theStringArray
is being constructed with an array containing NaN/float('nan')
, and that value is considered/treated different topd.NA
.There's a few other issues mentioning this error, but it wasn't obvious to me if they're the same:
Expected Output
The
broken
code should behave similarly to the very similarworking1
andworking2
. The output should be the same as theworking1
:Output of
pd.show_versions()
INSTALLED VERSIONS
commit : 5f648bf
python : 3.8.7.final.0
python-bits : 64
OS : Darwin
OS-release : 20.5.0
Version : Darwin Kernel Version 20.5.0: Sat May 8 05:10:31 PDT 2021; root:xnu-7195.121.3~9/RELEASE_ARM64_T8101
machine : arm64
processor : arm
byteorder : little
LC_ALL : None
LANG : en_AU.UTF-8
LOCALE : en_AU.UTF-8
pandas : 1.3.2
numpy : 1.20.2
pytz : 2021.1
dateutil : 2.8.1
pip : 21.2.4
setuptools : 49.2.1
Cython : None
pytest : 6.1.2
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : 2.9.1 (dt dec pq3 ext lo64)
jinja2 : 2.11.3
IPython : 7.22.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : 3.0.7
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : 1.7.1
sqlalchemy : 1.3.20
tables : None
tabulate : 0.8.9
xarray : None
xlrd : 2.0.1
xlwt : 1.3.0
numba : None
The text was updated successfully, but these errors were encountered: