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

Make private collection attributes singular#26062

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

Open
efiring wants to merge1 commit intomatplotlib:main
base:main
Choose a base branch
Loading
fromefiring:collection_private_singular_1

Conversation

efiring
Copy link
Member

PR summary

This replaces the part of#18592 that makes collection private attributes like_linewidths and_facecolors singular (_linewidth and_facecolor) to match their getters and setters.

PR checklist

@efiringefiring marked this pull request as draftJune 4, 2023 00:22
@efiringefiring mentioned this pull requestJun 4, 2023
7 tasks
@efiringefiring marked this pull request as ready for reviewJune 4, 2023 07:31
Copy link
Member

@story645story645 left a comment
edited
Loading

Choose a reason for hiding this comment

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

Since this is private, does this not need an API note?

@timhoffm
Copy link
Member

I'm -0.8 on this. There is a difference between the user API (set_facecolor()) and the internal data represenation. While a user can useset_facecolor('red'), we convert it into a (1, 4) array. The plural makes it clear that it is an iterable over the colors (which, yes, may contain only one element). Also internal expressions likelen(self._facecolors) read better thanlen(self._facecolor).

@efiringefiring mentioned this pull requestJun 5, 2023
1 task
@story645
Copy link
Member

There is a difference between the user API (set_facecolor()) and the internal data represenation

But get_facecolor is gonna return__facecolors so if someone needed the private variable for whatever reason, that's what they'd have to pull. I think 'especially since we have the color/colors mean different things API, it's a lot clearer when reading the code if the internal matches the public - otherwise I'd be double checking wait do we have another color parameter in the signature?

@timhoffm
Copy link
Member

timhoffm commentedJun 5, 2023
edited
Loading

I cannot follow your argument.facecolors is an alias tofacecolor. These are equivalent for the public API. There'll be always one of the two that won't match the internal naming. In fact,Collection.__init__ even uses the plural versions.

self._shading = shading
self._bbox = transforms.Bbox.unit()
self._bbox.update_from_data_xy(self._coordinates.reshape(-1, 2))
kwargs["antialiased"] = antialiased
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
kwargs["antialiased"] = antialiased

I think you can remove this, and remove antialiased from the signature above and then it is inkwargs already.

@story645
Copy link
Member

@timhoffm sorry should have double checked and now I'm annoyed at the public API and feel like the singular should get discouraged (the three ways to access the same thing is giving me hives).

@efiring
Copy link
MemberAuthor

@timhoffm, I think that I might have been the originator of the plurals long ago, so I am sympathetic to the argument that names for plural things should be plural, but over time there have been complaints about having some things plural and other similar thing singular, and the consensus at the time of#18592 was to shift the private variables to singular, and to use aliases so that collection kwargs could be singular or plural. The aliases were implemented, but not the private variable changes. The singular form was used in a change in mplot3d, however. So right now we have a bit of a mess. On balance, I think that moving everything to favor the singular will reduce confusion. The grammatical ugliness is an unfortunate side effect, but is outweighed by the simplification. Also, note that some of these sorts of variables can be singular or plural for the same object; and something originally designed as singular (like alpha) can end up being extended to be optionally plural.

@efiring
Copy link
MemberAuthor

The plural can be pretty ugly, too: "antialiaseds"? Really? And in general that can be plural for collections, but it is singular in QuadMesh.

@timhoffm
Copy link
Member

now I'm annoyed at the public API and feel like the singular should get discouraged

OTOH the singular versions are inherited fromArtist.

On the public API we're torn between

  • the "singular" inheritance from Artist
  • the somewhat justifiyable plural semantics
  • the constructor arguments
  • the aliasing

Overall, it's best to leave everything there as is.

In the internals, we can do whatever we want. I have no overview here, but if we have a singular-plural mixture we should definitively have a clear policy and unify this. The direction of the change may be open to discussion.


On a side-note: If I was to design this from scratch, the public API would be all-singular. You could have single values used as broadcastCircleCollection(..., facecolor="red") andCircleCollection(..., facecolor=["red", "green", "blue"]) work.

Internal naming would depend on normalization: If we carry the element around as is, it would be the public name (self._facecolor="red" /self._facecolor=["red", "green", "blue"]). If we normalize the parameter to an iterable I'd go with the pluralself._facecolors.

@efiring
Copy link
MemberAuthor

In another PR the public API could be nudged toward the singular by changing examples, docstrings, kwarg defaults and the alias table.

story645 reacted with thumbs up emoji

@tacaswelltacaswell added this to thev3.8.0 milestoneJun 8, 2023
@ksundenksunden modified the milestones:v3.8.0,v3.9.0Aug 8, 2023
Copy link
Member

@dstansbydstansby left a comment

Choose a reason for hiding this comment

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

I'm 👍 to this in principle, but looks like some tests need fixing first.

@efiring
Copy link
MemberAuthor

Thank you,@dstansby. I botched a rebase, so the current state of this PR is broken. Personally, I still think what it is trying to do is a step in the right direction--though a very minor improvement.@timhoffm, your last comment was not entirely clear to me: are you OK with this internal change, or not? I won't try to fix the PR unless it is clear it will go in.

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

@greglucasgreglucasgreglucas left review comments

@dstansbydstansbydstansby requested changes

@story645story645story645 approved these changes

Requested changes must be addressed to merge this pull request.

Assignees
No one assigned
Projects
None yet
Milestone
future releases
Development

Successfully merging this pull request may close these issues.

8 participants
@efiring@timhoffm@story645@dstansby@greglucas@tacaswell@QuLogic@ksunden

[8]ページ先頭

©2009-2025 Movatter.jp