Skip to content

DEPR: Deprecating Function Arguments #17828

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
gfyoung opened this issue Oct 9, 2017 · 5 comments
Closed

DEPR: Deprecating Function Arguments #17828

gfyoung opened this issue Oct 9, 2017 · 5 comments
Labels
Deprecate Functionality to remove in pandas
Milestone

Comments

@gfyoung
Copy link
Member

gfyoung commented Oct 9, 2017

When we want to deprecate and remove arguments, our general methodology has been to issue the deprecation warning ONLY when a non-default argument has been passed in.

However, @jorisvandenbossche pointed out in #17820 that this warnings framework does not take into account situations where the user EXPLICITLY passes in the default argument. Thus, we risk breaking downstream code in that case.

An alternative method would be to change the default argument (to some dummy) that we can use to catch this argument when passed in with the current accepted values.

While I have not seen this case emerge (patching is relatively painless, which might be why we haven't seen this issue on our tracker), I think it's worthwhile considering as we move forward with parameter deprecations + adjusting previous ones.

@gfyoung gfyoung added Community Deprecate Functionality to remove in pandas labels Oct 9, 2017
@jorisvandenbossche
Copy link
Member

I disagree with not raising for the default value is how it is typically done. I think it is rather the other way around (we normally put the deprecated kwarg to a default of None, to be able to distinguish the default and an actual user passed value). This is also how the deprecate_kwarg decorator works.

It might be that we just missed a few of those cases while reviewing in the PRs where you deprecated something, and so you have the impression that this is not the typical way deprecations are done (and likewise it is possible that I only reviewed mainly those PRs where we do it this way and thus I have the opposite impression)

Of course this issue is only relevant for a certain part of the deprecations (eg it is not relevant for deprecating/renaming kwargs that have no default value, or for changing a default value, or for deprecating/renaming a full method/class).
Let me go through the relevant ones for 0.21 release:

  • read_excel sheetname -> sheet_name kwarg rename, with a default of 0: this raises the warning when you pass sheetname=0 (as it is how the deprecate_kwarg decorator works)
  • take method convert kwarg: not raising for convert=True (IMO this should be fixed)
  • raise_on_errors kwarg in where with default of True: raises for the default (if you look at the implementation, it actually does if raise_on_error is not None: ... [raise warning])

It is true that it is making the signature less informative, but I think we need to have this warning, as it is the purpose of the warning that people can change their code before it breaks.

@jreback
Copy link
Contributor

jreback commented Oct 9, 2017

deprecated kwargs should always be None. Then in the code you can set them to the actual value; this allows detection and will show a warning if it was passed at all.

All of the examples by @jorisvandenbossche should be fixed.

@jreback jreback added this to the 0.21.0 milestone Oct 9, 2017
@gfyoung gfyoung removed the Community label Oct 9, 2017
@gfyoung gfyoung changed the title Deprecating Function Arguments DEPR: Deprecating Function Arguments Oct 9, 2017
gfyoung added a commit to forking-repos/pandas that referenced this issue Oct 10, 2017
Previously, we weren't issuing a warning if the user
happened to pass in the original default of "True",
which would cause downstream code to break.

Closes pandas-devgh-17828.
@gfyoung
Copy link
Member Author

gfyoung commented Oct 10, 2017

@jreback : Only the second one needs fixing. All others are according to what @jorisvandenbossche described above.

gfyoung added a commit to forking-repos/pandas that referenced this issue Oct 10, 2017
Previously, we weren't issuing a warning if the user
happened to pass in the original default of "True",
which would cause downstream code to break.

Closes pandas-devgh-17828.
gfyoung added a commit to forking-repos/pandas that referenced this issue Oct 10, 2017
Previously, we weren't issuing a warning if the user
happened to pass in the original default of "True",
which would cause downstream code to break.

Closes pandas-devgh-17828.
@jorisvandenbossche
Copy link
Member

Only the second one needs fixing.

Indeed, the others were to show we generally do it like this.
But one that is not in the list is the one of read_csv deprecation of tupleize_cols (the one that actually sparked this discussion)

gfyoung added a commit to forking-repos/pandas that referenced this issue Oct 10, 2017
Previously, we weren't issuing a warning if the user
happened to pass in the original default of "True",
which would cause downstream code to break.

Closes pandas-devgh-17828.
gfyoung added a commit to forking-repos/pandas that referenced this issue Oct 11, 2017
Previously, we weren't issuing a warning if the user
happened to pass in the original default of "True",
which would cause downstream code to break.

Closes pandas-devgh-17828.
gfyoung added a commit to forking-repos/pandas that referenced this issue Oct 12, 2017
Previously, we weren't issuing a warning if the user
happened to pass in the original default of "True",
which would cause downstream code to break.

Closes pandas-devgh-17828.
gfyoung added a commit to forking-repos/pandas that referenced this issue Oct 12, 2017
Previously, we weren't issuing a warning if the user
happened to pass in the original default of "True",
which would cause downstream code to break.

Closes pandas-devgh-17828.
gfyoung added a commit to forking-repos/pandas that referenced this issue Oct 12, 2017
Previously, we weren't issuing a warning if the user
happened to pass in the original default of "True",
which would cause downstream code to break.

Closes pandas-devgh-17828.
gfyoung added a commit to forking-repos/pandas that referenced this issue Oct 12, 2017
Previously, we weren't issuing a warning if the user
happened to pass in the original default of "True",
which would cause downstream code to break.

Closes pandas-devgh-17828.
TomAugspurger pushed a commit that referenced this issue Oct 12, 2017
Previously, we weren't issuing a warning if the user
happened to pass in the original default of "True",
which would cause downstream code to break.

Closes gh-17828.
@jorisvandenbossche
Copy link
Member

The original one that sparked the discussion still needs to be done I think: tupleize_cols in read_csv

gfyoung added a commit to forking-repos/pandas that referenced this issue Oct 13, 2017
Issue warnings on `read_csv` deprecated args
in full, even if the normal defaults were passed in.

Closes pandas-devgh-17828.
gfyoung added a commit to forking-repos/pandas that referenced this issue Oct 14, 2017
Issue warnings on `read_csv` deprecated args
in full, even if the normal defaults were passed in.

Closes pandas-devgh-17828.
gfyoung added a commit to forking-repos/pandas that referenced this issue Oct 14, 2017
Issue warnings on `read_csv` deprecated args
in full, even if the normal defaults were passed in.

Closes pandas-devgh-17828.
jreback pushed a commit that referenced this issue Oct 14, 2017
Issue warnings on `read_csv` deprecated args
in full, even if the normal defaults were passed in.

Closes gh-17828.
ghost pushed a commit to reef-technologies/pandas that referenced this issue Oct 16, 2017
Previously, we weren't issuing a warning if the user
happened to pass in the original default of "True",
which would cause downstream code to break.

Closes pandas-devgh-17828.
ghost pushed a commit to reef-technologies/pandas that referenced this issue Oct 16, 2017
Issue warnings on `read_csv` deprecated args
in full, even if the normal defaults were passed in.

Closes pandas-devgh-17828.
alanbato pushed a commit to alanbato/pandas that referenced this issue Nov 10, 2017
Previously, we weren't issuing a warning if the user
happened to pass in the original default of "True",
which would cause downstream code to break.

Closes pandas-devgh-17828.
alanbato pushed a commit to alanbato/pandas that referenced this issue Nov 10, 2017
Issue warnings on `read_csv` deprecated args
in full, even if the normal defaults were passed in.

Closes pandas-devgh-17828.
No-Stream pushed a commit to No-Stream/pandas that referenced this issue Nov 28, 2017
Previously, we weren't issuing a warning if the user
happened to pass in the original default of "True",
which would cause downstream code to break.

Closes pandas-devgh-17828.
No-Stream pushed a commit to No-Stream/pandas that referenced this issue Nov 28, 2017
Issue warnings on `read_csv` deprecated args
in full, even if the normal defaults were passed in.

Closes pandas-devgh-17828.
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
Projects
None yet
Development

No branches or pull requests

3 participants