-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: get_rename_function: add support for __getitem__ override #39921
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
Comments
we have an errors kwarg that would do what u want this proposal is a breaking change |
Hey @jreback ! Thanks for your answer. Which errors kwarg do you refer to? My use case is specifically with DataFrame.rename. I think I understand why this is a breaking change. It's because we can't assume that calling getitem is non breaking cause we don't know what is the implementation of the client right? |
I'm not 100% clear on the desired end-result. Is this similar to #11723? |
Well long story short I wanted to skip the call to __contains__ and use .get directly instead. And in terms of the need, yes! That's exactly what I want 😄🙌 |
Since #11723 seems like the aligned feature request, going to close this issue and encourage further discussion and support to happen in that issue |
Is your feature request related to a problem?
I would like to be able to use a subclass of UserDict with custom
__getitem__
implementation as a mapper for my dataframe columns. My use case is that I want to have a mapper with default remapping rules when the key is not present.Unfortunately, as the implementation checks for membership of the key before actually calling
__getitem__
, I am only able to do the behaviour by wrapping the UserDict with a lambda.Current implementation of get_rename_function in pandas:
My proposition is the following:
which functionally should result in the same behaviour.
The advantage for me is that
__getitem__
is called and I can process k to return my default mapping.I don't know however if this would have a significant performance impact. If so, alternatively I'd propose the following:
Then I could implement the
__call__
method. The downside however is that this could be a breaking change for some people that pass a subclass of a Mapping as well.What do you think?
The text was updated successfully, but these errors were encountered: