Skip to content

DataFrame.rename() function not throwing Error when non existing column pass in dict #23043

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
neelpuniwala opened this issue Oct 8, 2018 · 1 comment
Labels
Duplicate Report Duplicate issue or pull request

Comments

@neelpuniwala
Copy link

Code

df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})
df.rename(index=str, columns={"C": "a", "B": "c"},inplace = True)
df

#Output
        A       c
0	1	4
1	2	5
2	3	6

Problem description

the current behaviour of code is accepting any rename column dictionary. If rename column found in DataFrame, code renamed it but if rename column not found,Ideally, it should throw KeyError. Function will become more robust .

Expected Output

KeyError: 'C'

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.6.1.final.0 python-bits: 64 OS: Linux OS-release: 4.4.0-124-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_IN LOCALE: en_IN.ISO8859-1

pandas: 0.23.4
pytest: None
pip: 18.0
setuptools: 40.0.0
Cython: None
numpy: 1.15.0
scipy: None
pyarrow: None
xarray: None
IPython: 6.5.0
sphinx: None
patsy: None
dateutil: 2.7.3
pytz: 2018.5
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 1.0.1
sqlalchemy: None
pymysql: 0.9.2
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

@TomAugspurger
Copy link
Contributor

Duplicate of #13473

The current behavior is sometimes useful. We'd be happy to have an errors keyword to control how missing keys should be handled.

@TomAugspurger TomAugspurger added the Duplicate Report Duplicate issue or pull request label Oct 8, 2018
@TomAugspurger TomAugspurger added this to the No action milestone Oct 8, 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

2 participants