Skip to content

DEPR Deprecate mapper argument in rename? #44627

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
MarcoGorelli opened this issue Nov 26, 2021 · 14 comments · Fixed by #44672
Closed

DEPR Deprecate mapper argument in rename? #44627

MarcoGorelli opened this issue Nov 26, 2021 · 14 comments · Fixed by #44672
Labels
Deprecate Functionality to remove in pandas good first issue rename .rename, .rename_axis
Milestone

Comments

@MarcoGorelli
Copy link
Member

MarcoGorelli commented Nov 26, 2021

xref #40979 (comment)

thanks @MarcoGorelli i realize now why this is convoluted, will be glad to remove this in 2.0

@jreback not sure I understand what you mean - as in, to remove mapper in 2.0 and only support the index= and columns= calls? (and hence, introduce a deprecation warning in time for 1.4)

@MarcoGorelli MarcoGorelli added Deprecate Functionality to remove in pandas rename .rename, .rename_axis labels Nov 26, 2021
@jreback
Copy link
Contributor

jreback commented Nov 26, 2021

no what u mean is to fix the structure of the impl here
maybe we just need to make the structure in generic a private function to avoid having to handle the signature like this

@MarcoGorelli
Copy link
Member Author

MarcoGorelli commented Nov 26, 2021

OK, so rename rename in pandas/core/generic.py to _rename, and go back to the old signature for Series.rename, i.e.

    def rename(
        self,
        index=None,
        *,
        axis=None,
        copy=True,
        inplace=False,
        level=None,
        errors="ignore",
    ):

? Like this, mypy wouldn't complain about the incompatibility.
Wish I'd thought of this actually, it seems like a better solution than what I did.

If so, I think that could be done straight away, rather than having to wait for 2.0, it wouldn't alter anything user-facing

@jreback
Copy link
Contributor

jreback commented Nov 26, 2021

yeah i think that's right. its not worth trying to shoe-horn this in for methods which have a different signatture in series vs dataframe just to placate mypy, better to just have the impl be private.

@Varun270
Copy link
Contributor

@MarcoGorelli I tried to understand this issue and so far I understood that in pandas/core/generic.py we have to make the rename function private and make it _rename. Is that all? I am sure I am missing out on a lot.

@MarcoGorelli
Copy link
Member Author

Hey @Varun270 !

So, there's a few things to do:

  1. rename rename in pandas/core/generic.py to _rename
  2. update rename (in both pandas/core/frame.py and pandas/core/series.py to call super()._rename, rather than super().rename)
  3. revert some of the changes I made in TYP: Signature of "rename" incompatible with supertype "NDFrame" #40979 so that the signature of Series.rename becomes:
    def rename(
        self,
        index=None,
        *,
        axis=None,
        copy=True,
        inplace=False,
        level=None,
        errors="ignore",
    ) ->  Series | None:

If you open a PR (even if you're not sure about everything) and tag me I can help you along with this

@Varun270
Copy link
Contributor

Hey @Varun270 !

So, there's a few things to do:

  1. rename rename in pandas/core/generic.py to _rename
  2. update rename (in both pandas/core/frame.py and pandas/core/series.py to call super()._rename, rather than super().rename)
  3. revert some of the changes I made in TYP: Signature of "rename" incompatible with supertype "NDFrame" #40979 so that the signature of Series.rename becomes:
    def rename(
        self,
        index=None,
        *,
        axis=None,
        copy=True,
        inplace=False,
        level=None,
        errors="ignore",
    ) ->  Series | None:

If you open a PR (even if you're not sure about everything) and tag me I can help you along with this

I understood the first two points but will require your guidance on 3rd point as I don't know how can I revert changes done by someone else.

@Varun270
Copy link
Contributor

Currently in Series.rename the function rename looks like this -

def rename(
        self,
        index=None,
        *,
        axis=None,
        copy=True,
        inplace=False,
        level=None,
        errors="ignore",
    ):

So after reverting it would look like this -

    def rename(
        self,
        index=None,
        *,
        axis=None,
        copy=True,
        inplace=False,
        level=None,
        errors="ignore",
    ) ->  Series | None:

Is that what you are saying?

@MarcoGorelli
Copy link
Member Author

Currently in Series.rename the function rename looks like this -

Make sure to pull the latest changes, it doesn't quite look like that at the moment. Anyway,

So after reverting it would look like this -

Yes, it should look like that at the end

@Varun270
Copy link
Contributor

Currently in Series.rename the function rename looks like this -

Make sure to pull the latest changes, it doesn't quite look like that at the moment. Anyway,

So after reverting it would look like this -

Yes, it should look like that at the end

Okay, so I guess I would have to revert the changes first then rename the rename functions. How am I supposed to do that? Like should I do the usual git revert commit_id?

@MarcoGorelli
Copy link
Member Author

it's up to you how you do it

@Varun270
Copy link
Contributor

Alright, will do it!

@Varun270
Copy link
Contributor

@MarcoGorelli I found the commit that needed to be reverted but you have done some other changes in that commit apart from adding args to function rename. Here have a look at this - 40ecf6e
so should I proceed ahead since reverting it would revert some additional changes as well?

@MarcoGorelli
Copy link
Member Author

What can be reverted are:

  • changes to Series.rename (can just revert them all, and change super().rename to super()._rename
  • the extra tests in pandas/tests/series/methods/test_rename.py are no longer necessary

Might be easier to do this manually rather than reverting a commit using git. Up to you though, if you open a PR I'll take a look

@Varun270
Copy link
Contributor

What can be reverted are:

  • changes to Series.rename (can just revert them all, and change super().rename to super()._rename
  • the extra tests in pandas/tests/series/methods/test_rename.py are no longer necessary

Might be easier to do this manually rather than reverting a commit using git. Up to you though, if you open a PR I'll take a look

Yeah, even I was thinking that manually doing these changes would be much easier for me. Will create a PR.

Varun270 added a commit to Varun270/pandas that referenced this issue Nov 29, 2021
@jreback jreback added this to the 1.4 milestone Dec 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Deprecate Functionality to remove in pandas good first issue rename .rename, .rename_axis
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants