You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I have a pandas dataframe with duplicate column names and I use the method df.to_dict(orient='tight') it throws the following UserWarning:
"DataFrame columns are not unique, some columns will be omitted."
This error makes sense for creating dictionary from a pandas dataframe with columns as dictionary keys but not in the tight orientation where columns are placed into a columns list value.
It should not throw this warning at all with orient='tight'.
Expected Behavior
Do not throw UserWarning when there are duplicate column names in a pandas dataframe if the following parameter is set: df.to_dict(oreint='tight')
Thanks for the report! Your example doesn't seem to be reproducing this warning because df will end up having only 2 unique columns A and B
But yes, the warning is triggered when the DataFrame has duplicate columns and I agree that shouldn't be the case when orient='tight'. PRs to fix this are welcome!
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
If I have a pandas dataframe with duplicate column names and I use the method df.to_dict(orient='tight') it throws the following UserWarning:
"DataFrame columns are not unique, some columns will be omitted."
This error makes sense for creating dictionary from a pandas dataframe with columns as dictionary keys but not in the tight orientation where columns are placed into a columns list value.
It should not throw this warning at all with orient='tight'.
Expected Behavior
Do not throw UserWarning when there are duplicate column names in a pandas dataframe if the following parameter is set: df.to_dict(oreint='tight')
Installed Versions
INSTALLED VERSIONS
commit : bdc79c1
python : 3.11.4.final.0
python-bits : 64
OS : Darwin
OS-release : 23.4.0
Version : Darwin Kernel Version 23.4.0: Fri Mar 15 00:10:42 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6000
machine : arm64
processor : arm
byteorder : little
LC_ALL : None
LANG : None
LOCALE : en_US.UTF-8
pandas : 2.2.1
numpy : 1.26.4
pytz : 2024.1
dateutil : 2.9.0.post0
setuptools : 68.2.0
pip : 23.2.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 5.2.1
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2024.1
qtpy : None
pyqt5 : None
The text was updated successfully, but these errors were encountered: