-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: df.assign no longer works with multilevel columns #61295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is a python limitation. You're using tuple unpacking to pass in arguments to a function. Function argument names have to be valid variable names. https://stackoverflow.com/questions/65392503/keyword-error-generated-when-passing-a-dictionary-to-a-function-with-tuples-as-t |
Thanks for raising this! The https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.assign.html Technically speaking this isn't a pandas bug, but maybe pandas could consider supporting tuple keys? |
this is not possible (with the current signature), the error is thrown directly by the python interpreter. In [1]: def foo(**kwargs):
...: print(kwargs)
...:
In [2]: foo(**{('C', 'one'): 2})
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[1], line 1
----> 1 foo(**{('C', 'one'): 2})
TypeError: keywords must be strings |
Agreed @asishm - nothing can be done here. Closing. |
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
Issue Description
The final line reports the error: TypeError: keywords must be strings
Expected Behavior
It should create a new column ("C", 'one') with 1,2,3 in it.
Installed Versions
INSTALLED VERSIONS
commit : 0691c5c
python : 3.12.3
python-bits : 64
OS : Windows
OS-release : 11
Version : 10.0.26100
machine : AMD64
processor : Intel64 Family 6 Model 154 Stepping 4, GenuineIntel
byteorder : little
LC_ALL : None
LANG : en
LOCALE : English_Australia.1252
pandas : 2.2.3
numpy : 1.26.4
pytz : 2024.1
dateutil : 2.9.0.post0
pip : 25.0.1
Cython : None
sphinx : 7.3.7
IPython : 8.30.0
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.3
blosc : None
bottleneck : 1.4.2
dataframe-api-compat : None
fastparquet : None
fsspec : None
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : 3.1.6
lxml.etree : 5.3.0
matplotlib : 3.10.0
numba : None
numexpr : 2.10.1
odfpy : None
openpyxl : 3.1.5
pandas_gbq : None
psycopg2 : None
pymysql : None
pyarrow : 19.0.0
pyreadstat : 1.2.7
pytest : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.15.2
sqlalchemy : None
tables : None
tabulate : 0.9.0
xarray : None
xlrd : None
xlsxwriter : 3.1.1
zstandard : None
tzdata : 2023.3
qtpy : 2.4.1
pyqt5 : None
The text was updated successfully, but these errors were encountered: