BUG: df.to_dict(orient='tight') raises UserWarning incorrectly for duplicate columns · Issue #58281 · pandas-dev/pandas (original) (raw)

Pandas version checks

Reproducible Example

import pandas as pd df = pd.DataFrame({ 'A': [1, 2, 3], 'B': [4, 5, 6], 'A': [7, 8, 9] }) df.to_dict(orient='tight')

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