Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Deprecate positional use of most arguments of plotting functions#27786

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
tacaswell merged 2 commits intomatplotlib:mainfromtimhoffm:kwonly
Apr 8, 2024

Conversation

timhoffm
Copy link
Member

This increases maintainability for developers and disallows bad practice of passing lots of positional arguments for users. If in doubt, I've erred on the side of allowing as much positional arguments
as possible as long as the intent of a call is still readable.

Note: This was originally motivated by bxp() and boxplot() having many overlapping parameters but differently ordered.
While at it, I think it's better to rollout the change to all plotting functions and communicate that in one go rather than having lots of individual change notices over time. Also, the freedom to reorder parameters only sets in after the deprecation. So let's start this now.

story645 reacted with thumbs up emoji
@timhoffmtimhoffm added this to thev3.9.0 milestoneFeb 13, 2024
@timhoffmtimhoffm marked this pull request as draftFebruary 13, 2024 16:55
Comment on lines +4 to +5
Many plotting functions will restrict positional arguments to the first few parameters
in the future. All further configuration parameters will have to be passed as keyword
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Is there any way to have some measure of consistency on which parameters are positional only (like for example the data parameters?)

Copy link
MemberAuthor

@timhoffmtimhoffmFeb 13, 2024
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The central question is:Is code using the positional parameters understandable without knowing the signature? Mostly this results in positional data parameters. But with some exceptions:

  • fmt is allowed positionally - inspired byplot
  • I’ve still allowedbins in histograms because fromhist(data, 20) it's conceivable that the inter is bins(debatable, but err on the permissive side)
  • Withhlines I've gone to the extreme and still allowed color and linestyles because if somebody has writtenhlines(y, xmin, xmax, 'red', 'dashed') that's quite clear and I don't want to break their code.

@ksunden
Copy link
Member

There seems to be an order dependence inboilerplate.py that is expecting deprecators to be the outermost decorator rather than just anywhere:

meth=getattr(class_,called_name)
decorator=_api.deprecation.DECORATORS.get(meth)
# Generate the wrapper with the non-kwonly signature, as it will get
# redecorated with make_keyword_only by _copy_docstring_and_deprecators.
ifdecoratoranddecorator.funcis_api.make_keyword_only:
meth=meth.__wrapped__

For instance,violinplot in this branch has both the_preprocess_data decorator and themake_keyword_only decorator, but the_api.deprecation.DECORATORS.get returnsNone:

>>>mpl.__version__'3.9.0.dev1136+g3edfce3b0e'>>>mpl._api.deprecation.DECORATORS.get(mpl.axes.Axes.violinplot)>>>mpl._api.deprecation.DECORATORS.get(mpl.axes.Axes.violinplot.__wrapped__)functools.partial(<functionmake_keyword_onlyat0x7f641386bce0>,'3.9','vert')>>>mpl._api.deprecation.DECORATORS.get(mpl.axes.Axes.violin)functools.partial(<functionmake_keyword_onlyat0x7f641386bce0>,'3.9','vert')

If you reach into__wrapped__ or if you inspectviolin (which has only the one decorator) the lookup works.

DECORATORS is just a dictionary that gets added to with the wrapped version of the method as keys and the decorator itself as value. Once it has been wrapped again, the connection is lost.

Thus I think the easiest corrective action to make pyplot not prematurely implement kwonly args (without warning) is to move the deprecations to be the outermost decorators... That or the boilerplate code needs to grow to search the entiremeth.__wrapped__ sequence from outside in rather than only looking at the outermost (which would also make it more robust to multiple deprecatoions on the same method).

At first I thought it was some of the code I wrote in boilerplate to add type hints in, but I confirmed that I do not change the param types from themeth parameter extracted by these lines (which predate those changes).

timhoffm reacted with heart emojitimhoffm reacted with rocket emoji

@github-actionsgithub-actionsbot added the Documentation: examplesfiles in galleries/examples labelFeb 13, 2024
@github-actionsgithub-actionsbot removed the Documentation: examplesfiles in galleries/examples labelFeb 13, 2024
@github-actionsgithub-actionsbot added the Documentation: examplesfiles in galleries/examples labelFeb 13, 2024
@timhoffmtimhoffm marked this pull request as ready for reviewFebruary 13, 2024 23:03
@timhoffmtimhoffmforce-pushed thekwonly branch 2 times, most recently from7e10766 to87b8b2eCompareMarch 6, 2024 21:30
@ksundenksunden removed this from thev3.9.0 milestoneMar 6, 2024
@ksundenksunden added this to thev3.10.0 milestoneMar 6, 2024
@ksunden
Copy link
Member

In discussion with@tacaswell and@QuLogic we decided to push this to early 3.10 rather than late 3.9.

This increases maintainability for developers and disallowsbad practice of passing lots of positional arguments for users.If in doubt, I've erred on the side of allowing as much positionalargumentsas possible as long as the intent of a call is still readable.Note: This was originally motivated by bxp() and boxplot() having manyoverlapping parameters but differently ordered.While at it, I think it's better to rollout the change toall plotting functions and communicate that in one gorather than having lots of individual change notices overtime. Also, the freedom to reorder parameters only setsin after the deprecation. So let's start this now.
... to the error message, that gets thrown if it is not.
@@ -4636,6 +4644,7 @@ def invalid_shape_exception(csize, xsize):
colors = None # use cmap, norm after collection is created
return c, colors, edgecolors

@_api.make_keyword_only("3.9", "marker")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I can see an arguament for pushing this one deeper

ax.scatter(x,y,s,c,'o')

scans reasonably well, but I suspect is rare.

Copy link
Member

@tacaswelltacaswell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

We should be open to feedback on these if they turn out to be more disruptive than we anticipate.

timhoffm reacted with thumbs up emoji
@tacaswell
Copy link
Member

The appveyor failure is issues with gobject importing so I'm going to merge over that.

I'm going to merge this (as we have branched for 3.9) to get it in as early as possible and to make the odds of finding major disruptions down stream as high as possible.

I'm torn if the deprecation note on this is exuberant enough for the scale of the change.

@tacaswelltacaswell merged commit5e0aa54 intomatplotlib:mainApr 8, 2024
@timhoffmtimhoffm deleted the kwonly branchApril 8, 2024 18:02
@timhoffm
Copy link
MemberAuthor

I'm torn if the deprecation note on this is exuberant enough for the scale of the change.

I believe most affected users will learn from the runtime warning anyway. But feel free to change the note.

@rcomer
Copy link
Member

In discussion with@tacaswell and@QuLogic we decided to push this to early 3.10 rather than late 3.9.

The warnings still say 3.9 👀 Should we correct them this far down the path?

@timhoffm
Copy link
MemberAuthor

It doesn't matter too much. But we should watch out that we don't shorten expiration because we noted a version number too low. So likely the simplest thing is updating.

rcomer reacted with thumbs up emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@story645story645story645 left review comments

@ksundenksundenksunden approved these changes

@tacaswelltacaswelltacaswell approved these changes

Assignees
No one assigned
Labels
API: changesDocumentation: examplesfiles in galleries/examples
Projects
None yet
Milestone
v3.10.0
Development

Successfully merging this pull request may close these issues.

5 participants
@timhoffm@ksunden@tacaswell@rcomer@story645

[8]ページ先頭

©2009-2025 Movatter.jp