Skip to content

BUG: Problem in assigning multiple items to ListType array members #53178

Open
@martinschi

Description

@martinschi

if is_list_like(value):

^^^ this guards against assigning "list like" objects to array member. However if the array itself is array of ListType members, then the code should allow it, otherwise there's seemingly no way how to assign multiple items to single array position.

E.g.,

import pyarrow as pa
import pandas as pd

list_str_type = pa.list_(pa.string())
ser = pd.Series([['foo'], ['bar'], ['foobar']], dtype=pd.ArrowDtype(list_str_type))

a = pa.array(['hello', 'world'], type=pa.string())
s = pa.scalar(['hello', 'world'], type=list_str_type)

# following fails with ValueError("Length of indexer and values mismatch")
ser[1] = a

# following also fails with ValueError("Length of indexer and values mismatch")
ser[1] = s

pd.show_versions()

INSTALLED VERSIONS

commit : 37ea63d
python : 3.11.3.final.0
python-bits : 64
OS : Darwin
OS-release : 22.4.0
Version : Darwin Kernel Version 22.4.0: Mon Mar 6 21:00:17 PST 2023; root:xnu-8796.101.5~3/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 2.0.1
numpy : 1.24.3
pytz : 2023.3
dateutil : 2.8.2
setuptools : 65.5.0
pip : 23.1.2
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 12.0.0
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Arrowpyarrow functionalityBugNested DataData where the values are collections (lists, sets, dicts, objects, etc.).

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions