Skip to content

BUG: Assigning pd.NA to StringDtype column causes "Unknown error: Wrapping .. failed" after pd.concat with PyArrow #64320

Description

@askalonso

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

I get a pyarrow.lib.ArrowException: Unknown error: Wrapping � failed when running this in a new environment with only pandas and pyarrow installed. Confirmed error on Windows (python 3.13) and Ubuntu (python 3.12). I've included pd.show_versions() of the Ubuntu replication.

import pandas as pd

df = pd.concat([
    pd.DataFrame({"a": ["x"] * 33, "b": ["x"] * 33}),
    pd.DataFrame({"a": ["x"] * 34, "b": ["x"] * 34}),
])

for i in range(1, 50):
    df.loc[[0], "a"] = pd.NA

Traceback

I've replaced part of the full file path with "~"

Details

Traceback (most recent call last):
File "~/bug-repro/repro_fail_single_row_list.py", line 9, in
df.loc[[0], "a"] = pd.NA
~~~~~~^^^^^^^^^^
File "~/bug-repro/.venv/lib/python3.12/site-packages/pandas/core/indexing.py", line 941, in setitem
iloc._setitem_with_indexer(indexer, value, self.name)
File "~/bug-repro/.venv/lib/python3.12/site-packages/pandas/core/indexing.py", line 2480, in _setitem_with_indexer
self._setitem_with_indexer_split_path(indexer, value, name)
File "~/bug-repro/.venv/lib/python3.12/site-packages/pandas/core/indexing.py", line 2571, in _setitem_with_indexer_split_path
self._setitem_single_column(loc, value, pi)
File "~/bug-repro/.venv/lib/python3.12/site-packages/pandas/core/indexing.py", line 2709, in _setitem_single_column
self.obj._mgr.column_setitem(loc, plane_indexer, value)
File "~/bug-repro/.venv/lib/python3.12/site-packages/pandas/core/internals/managers.py", line 1521, in column_setitem
self.iset(loc, new_mgr._block.values, inplace=True)
File "~/bug-repro/.venv/lib/python3.12/site-packages/pandas/core/internals/managers.py", line 1299, in iset
return self._iset_single(
^^^^^^^^^^^^^^^^^^
File "~/bug-repro/.venv/lib/python3.12/site-packages/pandas/core/internals/managers.py", line 1482, in _iset_single
blk.set_inplace(slice(iloc, iloc + 1), value, copy=copy)
File "~/bug-repro/.venv/lib/python3.12/site-packages/pandas/core/internals/blocks.py", line 1965, in set_inplace
self.values[:] = values
~~~~~~~~~~~^^^
File "~/bug-repro/.venv/lib/python3.12/site-packages/pandas/core/arrays/arrow/array.py", line 2417, in setitem
value = self._maybe_convert_setitem_value(value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "~/bug-repro/.venv/lib/python3.12/site-packages/pandas/core/arrays/string_arrow.py", line 289, in _maybe_convert_setitem_value
value = np.array(value, dtype=object, copy=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "~/bug-repro/.venv/lib/python3.12/site-packages/pandas/core/arrays/arrow/array.py", line 869, in array
return self.to_numpy(dtype=dtype, copy=copy)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "~/bug-repro/.venv/lib/python3.12/site-packages/pandas/core/arrays/arrow/array.py", line 1895, in to_numpy
result[~mask] = data[~mask]._pa_array.to_numpy()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "pyarrow/table.pxi", line 531, in pyarrow.lib.ChunkedArray.to_numpy
File "pyarrow/error.pxi", line 92, in pyarrow.lib.check_status
failed.lib.ArrowException: Unknown error: Wrapping

Issue Description

When assigning pd.NA (or other None-types) to a string-column in a dataframe with two or more string-columns, it eventually fails with an "Unknown error: Wrapping ... failed" when the dataframes are large enough. If you decrease the size of either dataframe in the reproducible example the error goes away. I've confirmed that it happens both on pandas main-branch (3.1.0.dev0+218.gea4d2c0b27) and 3.0.1.

Only happens with Pandas and PyArrow. It doesn't always happen on the first pd.NA assignment (thus the for loop). Also, it only happens with two or more string columns in the dataframe, if column "b" is dropped, the issue goes away. If you set elements with single indices df.loc[0, "a"] = pd.NA instead, the error also seems to dissapear.

From my investigations, it only seems to happen when the total size in memory of the column in the dataframe after the concat is above a certain threshold. Meaning that if you increase the length of the strings in column "a", the threshold in order to trigger the error decreases. Example of a shorter dataframe that also fails:

df = pd.concat([
    pd.DataFrame({"a": ["xx"] * 18, "b": ["x"] * 18}),
    pd.DataFrame({"a": ["xx"] * 17, "b": ["x"] * 17}),
])

The size of the strings in column "b" doesn't seem to impact if an error occurs or not.

If you set more elements to pd.NA at the same time, the threshold for when the error occurs increases. Example:

df = pd.concat([
    pd.DataFrame({"a": ["x"] * 36, "b": ["x"] * 36}),
    pd.DataFrame({"a": ["x"] * 35, "b": ["x"] * 35}),
])

for i in range(1, 50):
    df.loc[[0, 1, 2], "a"] = pd.NA

Here the size of the dataframe had to be increased to trigger the error.

A workaround is to set the storage type of the dataframes to "python":

df = pd.concat([
    pd.DataFrame({"a": ["x"] * 33, "b": ["x"] * 33}, dtype=pd.StringDtype(storage="python")),
    pd.DataFrame({"a": ["x"] * 34, "b": ["x"] * 34}, dtype=pd.StringDtype(storage="python")),
])

I've never raised an issue on github before so I'd be grateful for some feedback on anything that could be improved :)

Expected Behavior

The expected behavior is that no errors happen, and the first row in column "a" is pd.NA.

Installed Versions

Details INSTALLED VERSIONS ------------------ commit : ea4d2c0 python : 3.12.3 python-bits : 64 OS : Linux OS-release : 6.14.0-1017-azure Version : #17~24.04.1-Ubuntu SMP Mon Dec 1 20:10:50 UTC 2025 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : None LANG : C.UTF-8 LOCALE : C.UTF-8

pandas : 3.1.0.dev0+218.gea4d2c0b27
numpy : 2.4.2
dateutil : 2.9.0.post0
pip : None
Cython : None
sphinx : None
IPython : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
bottleneck : 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
psycopg2 : None
pymysql : None
pyarrow : 23.0.1
pyiceberg : None
pyreadstat : None
pytest : None
python-calamine : None
pytz : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
qtpy : None
pyqt5 : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Arrowpyarrow functionalityBugStringsString extension data type and string data

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions