Skip to content

BUG: Raname a column to have the same name to other column creates a DataFrame with two columns with the same name #45486

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

Closed
2 of 3 tasks
fedegr opened this issue Jan 20, 2022 · 1 comment

Comments

@fedegr
Copy link

fedegr commented Jan 20, 2022

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

df = pd.DataFrame({"a":[1], "b":[2]})
df.rename(columns={"b": "a"})
#    a  a
# 0  1  2

Issue Description

Renaming a column to have a name of another column generates a new DataFrame with 2 columns with the same name

Expected Behavior

I would expect an error or the old column to be replaced.

Installed Versions

Matplotlib created a temporary config/cache directory at /tmp/matplotlib-sqyn173n because the default path (/config/matplotlib) is not a writable directory; it is highly recommended to set the MPLCONFIGDIR environment variable to a writable directory, in particular to speed up the import of Matplotlib and to better support multiprocessing.

INSTALLED VERSIONS
------------------
commit           : 66e3805b8cabe977f40c05259cc3fcf7ead5687d
python           : 3.8.12.final.0
python-bits      : 64
OS               : Linux
OS-release       : 5.11.0-1026-gcp
Version          : #29~20.04.1-Ubuntu SMP Fri Jan 7 12:24:31 UTC 2022
machine          : x86_64
processor        : 
byteorder        : little
LC_ALL           : en_US.UTF-8
LANG             : en_US.UTF-8
LOCALE           : en_US.UTF-8

pandas           : 1.3.5
numpy            : 1.22.1
pytz             : 2021.3
dateutil         : 2.8.2
pip              : 21.2.dev0
setuptools       : 56.0.0
Cython           : None
pytest           : None
hypothesis       : None
sphinx           : None
blosc            : None
feather          : None
xlsxwriter       : None
lxml.etree       : None
html5lib         : 1.1
pymysql          : None
psycopg2         : None
jinja2           : 3.0.1
IPython          : None
pandas_datareader: None
bs4              : None
bottleneck       : None
fsspec           : None
fastparquet      : None
gcsfs            : None
matplotlib       : 3.4.3
numexpr          : None
odfpy            : None
openpyxl         : None
pandas_gbq       : None
pyarrow          : None
pyxlsb           : None
s3fs             : None
scipy            : 1.4.1
sqlalchemy       : 1.4.23
tables           : None
tabulate         : None
xarray           : None
xlrd             : None
xlwt             : None
numba            : None
@fedegr fedegr added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jan 20, 2022
@fedegr fedegr changed the title BUG: BUG: Raname a column to have the same name to other column creates a DataFrame with two columns with the same name Jan 20, 2022
@phofl
Copy link
Member

phofl commented Jan 20, 2022

This behaves as expected, duplicated column names are valid.

@phofl phofl closed this as completed Jan 20, 2022
@phofl phofl added this to the No action milestone Jan 20, 2022
@phofl phofl added Usage Question and removed Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jan 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants