Skip to content

Rename silently ignores missing key #24136

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
ghost opened this issue Dec 7, 2018 · 1 comment
Closed

Rename silently ignores missing key #24136

ghost opened this issue Dec 7, 2018 · 1 comment
Labels
Duplicate Report Duplicate issue or pull request

Comments

@ghost
Copy link

ghost commented Dec 7, 2018

Code Sample, a copy-pastable example if possible

import pandas as pd
df = pd.DataFrame([{'a': 1, 'b': 2}, {'a': 10, 'b': 20}])              
df.rename(columns={'XXX': 'YYY'})                                      

Out[16]: 
    a   b
0   1   2
1  10  20

Problem description

If I try to rename a column but it doesn't exist, I want to be alerted about this. From the Zen of Python, "Errors should not pass silently."

Currently, there is no indication of a failure, I just silently get a different result than expected.

Expected Output

KeyError('XXX')

Output of pd.show_versions()

[paste the output of pd.show_versions() here below this line]
INSTALLED VERSIONS

commit: None
python: 3.6.6.final.0
python-bits: 64
OS: Linux
OS-release: 4.15.0-39-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.23.4
pytest: 3.9.3
pip: 18.1
setuptools: 40.4.3
Cython: None
numpy: 1.15.2
scipy: 1.1.0
pyarrow: None
xarray: None
IPython: 7.0.1
sphinx: None
patsy: 0.5.1
dateutil: 2.7.3
pytz: 2018.5
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 3.0.2
openpyxl: 2.5.8
xlrd: 1.1.0
xlwt: None
xlsxwriter: None
lxml: 4.2.5
bs4: 4.6.3
html5lib: 1.0.1
sqlalchemy: 1.2.12
pymysql: None
psycopg2: 2.7.6.1 (dt dec pq3 ext lo64)
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

@WillAyd WillAyd added the Duplicate Report Duplicate issue or pull request label Dec 7, 2018
@WillAyd
Copy link
Member

WillAyd commented Dec 7, 2018

Duplicate of #13473 if you'd like to take a look PR would be welcome

@WillAyd WillAyd closed this as completed Dec 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request
Projects
None yet
Development

No branches or pull requests

1 participant