BUG: Confusing Behavior When Assigning DataFrame Columns Using omegaconf.ListConfig
#61439
Open
2 of 3 tasks
Labels
Bug
Indexing
Related to indexing on series/frames, not to indexes themselves
Needs Discussion
Requires discussion from core team before further action
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
Error message:
ValueError: Cannot set a DataFrame with multiple columns to the single column ['a', 'b']
Issue Description
When using an
omegaconf.ListConfig
object to select columns in a Pandas DataFrame, the assignment operation fails with aValueError
, even though the shapes, columns, and indices of the left-hand side (LHS) and right-hand side (RHS) match perfectly. This behavior is unexpected and confusing, as it is not immediately clear that the issue is caused by the type of the column selector.Expected Behavior:
The assignment should succeed, as the shapes, columns, and indices of the LHS and RHS match.
Likely Context of Encountering This:
This issue is likely to occur in workflows where omegaconf.ListConfig is used to manage configurations, such as specifying column names for normalization or other data processing tasks. For example:
Workaround:
Convert the ListConfig object to a standard Python list before using it in Pandas operations:
Why This Is Confusing:
Proposed Solution:
isinstance(cols, Sequence)
is True.Expected Behavior
The assignment should succeed, as the shapes, columns, and indices of the LHS and RHS match.
Installed Versions
INSTALLED VERSIONS
commit : 0691c5c
python : 3.11.7
python-bits : 64
OS : Darwin
OS-release : 23.6.0
Version : Darwin Kernel Version 23.6.0: Fri Nov 15 15:13:28 PST 2024; root:xnu-10063.141.1.702.7~1/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.UTF-8
pandas : 2.2.3
numpy : 1.26.4
pytz : 2025.2
dateutil : 2.9.0.post0
pip : 24.0
Cython : None
sphinx : None
IPython : 9.1.0
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.13.3
blosc : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : 2025.3.2
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : 3.1.6
lxml.etree : 4.9.4
matplotlib : 3.10.1
numba : 0.58.1
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
psycopg2 : None
pymysql : None
pyarrow : 19.0.1
pyreadstat : None
pytest : 8.3.5
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.15.2
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
tzdata : 2025.2
qtpy : None
pyqt5 : None
The text was updated successfully, but these errors were encountered: