question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ENH: add errors='raise' option to rename

See original GitHub issue

Is there a reason that .rename doesn’t raise if keys are supplied that don’t exist? This caught me out a couple of times:

In [14]: import pandas as pd

In [15]: df=pd.DataFrame({'a': [1,2], 'b': [3,4]})

In [16]: df
Out[16]: 
   a  b
0  1  3
1  2  4

In [17]: df.rename(columns={'a': 'c'})
Out[17]: 
   c  b
0  1  3
1  2  4
# ok

In [18]: df.rename(columns={'d': 'c'})
Out[18]: 
   a  b
0  1  3
1  2  4

# this should raise?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
ghostcommented, Dec 7, 2018

Is there a particular reason why the default value would be “ignore” for rename? If I’m renaming keys in a mapping but one isn’t there, I normally anticipate a KeyError. A deprecation period would be necessary, of course – I think a similar change has occurred recently with missing columns for loc.

0reactions
bala-analyticscommented, Jun 17, 2020

Thanks. Sorry missed that errors = ‘raise’ option

From: Tom Augspurger notifications@github.com Sent: 16 June 2020 21:27 To: pandas-dev/pandas pandas@noreply.github.com Cc: Bhaskaran, Balakrishnan GSUK-PTX/D/S B.Bhaskaran@shell.com; Mention mention@noreply.github.com Subject: Re: [pandas-dev/pandas] ENH: add errors=‘raise’ option to rename (#13473)

@bala-analyticshttps://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fbala-analytics&data=02|01|b.bhaskaran%40shell.com|bc50fd93bf194f3efdfe08d81233ae88|db1e96a8a3da442a930b235cac24cd5c|0|0|637279360500483631&sdata=CZVLf7jrfBzbxr4IkiXVQNGkABTv2g9bmxodCM2fa9o%3D&reserved=0 the original example correctly raises with df.rename(columns={‘d’: ‘c’}, errors=“raise”).

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fpandas-dev%2Fpandas%2Fissues%2F13473%23issuecomment-644994081&data=02|01|b.bhaskaran%40shell.com|bc50fd93bf194f3efdfe08d81233ae88|db1e96a8a3da442a930b235cac24cd5c|0|0|637279360500493620&sdata=ZTTB3a%2F86Fc8%2BlJSuHWyjNiWS6gSjGyMQEkCqRxuMIU%3D&reserved=0, or unsubscribehttps://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAO6KXJRJB5BLM5FQQZ3JGG3RW7ISZANCNFSM4CHCIO6A&data=02|01|b.bhaskaran%40shell.com|bc50fd93bf194f3efdfe08d81233ae88|db1e96a8a3da442a930b235cac24cd5c|0|0|637279360500493620&sdata=UeQR5zHkJKZMO9szJhmIE82ebBcwnCDDtDr9J%2BR9ONU%3D&reserved=0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error handler package - Automation Anywhere Documentation
The Error handler package contains actions that enable you. ... Catch block by using the Catch > On error, continue with next action...
Read more >
SLIN/EC error in structure enhancement (standard structure is ...
I'm making changes in a very old program and am getting an extended check error (not warning even though the message text says...
Read more >
How to Fix No Enhancement Tab in Sound Settings ... - YouTube
How to Fix No Enhancement Tab in Sound Settings on Windows 10So you want to boost and enhance the audio on your computer, ......
Read more >
PEP 8 – Style Guide for Python Code
The guidelines provided here are intended to improve the readability of code and make it consistent across the wide spectrum of Python code....
Read more >
WhatsNew - FSL - FslWiki
This is now the default option for all FMRI to structural registrations as it ... by hand) in order to improve segmentation and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found