-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
MNT: unify code path of set, update, setp #5599
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
MNT: unify code path of set, update, setp #5599
Conversation
A follow on to this might be to implement a priority lookup to sort the key/value pairs instead of alphabetical sorting, but I am not sure if that is replicating functionality already in traitlets. |
I would be +1 on implementing a proper lookup order. The reversed(IIRC) On Tue, Dec 1, 2015 at 11:35 AM, Thomas A Caswell notifications@github.com
|
|
||
The methods `matplotlib.artist.Artist.set`, | ||
`matplotlib.Artist.update`, and the function `matplotlib.artist.setp` | ||
now use a common codepath to loop up how to update the given artist |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
loop up how to ? (I think?) The sentence is a little unclear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed and force-pushed
Single code path for the property -> setter lookup logic.
self.pchanged() | ||
self.stale = True | ||
return ret | ||
|
||
def _update_property(self, k, v): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this could be an embedded function in update()
, since it isn't used from anywhere else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point, when I started I didn't think I would be able to use update
everywhere else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on second thought, wouldn't that result in re-defining the function everytime through call to update
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No -- Python will compile the function only once -- it only redefines the local variables each time.
4f8343b
to
63f4437
Compare
changed = False | ||
try: | ||
ret = [self._update_property(k, v) | ||
for k, v in sorted(props.items(), reverse=True)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The sorting by key name is just to prevent any non-deterministic behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and makes color/facecolor/edgecolor go in the right order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Partly. It is also to have a priority structure. If someone defines both
"color" and "facecolor" at the same time, the current behavior is for color
to take precedence over facecolor, IIRC.
On Tue, Dec 1, 2015 at 11:51 AM, Michael Droettboom <
notifications@github.com> wrote:
In lib/matplotlib/artist.py
#5599 (comment):@@ -845,21 +845,46 @@ def update(self, props):
"""
store = self.eventson
self.eventson = False
changed = False
try:
ret = [self._update_property(k, v)
for k, v in sorted(props.items(), reverse=True)]
The sorting by key name is just to prevent any non-deterministic behavior?
—
Reply to this email directly or view it on GitHub
https://github.com/matplotlib/matplotlib/pull/5599/files#r46304017.
This is cool, and I'm always happy to see PRs that reduce total lines of code ;) Maybe this is a minor point, but it seems that |
Hide private helper method more thoroughly.
I changed a list to a set literal, this can not be back-ported to 1.5.x. |
Agree with @mdboom. Let setp be the only place where sorting happens. I On Tue, Dec 1, 2015 at 11:55 AM, Michael Droettboom <
|
restore old behavior
Make one call to `update` with the ordered dict rather than one call per element.
Add the ability to set the precedence of properties when updating multiple properties on once. This adds a class-level attribute `Artist._prop_order` which is a dictionary keyed on property names with integer values. When using `set` or `setp` the properties will be applied in descending order by value then by name.
If we're concerned about subtle changes in behavior, the new zero-tolerance test suite seems to be pretty good at rooting that out. @tacaswell: if you wanted, you could base this on my zero tolerance branch and see if any additional tests are failing beyond the dozen or so that are failing on that branch presently. |
Ended up landing on |
properties (either using the setter methods or an attribute/property). | ||
|
||
The behavior of `matplotlib.Artist.update` is slightly changed to | ||
returna a list of the returned values from the setter methods to avoid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
returna -> return
I rebased it locally and have the same 11 failures. |
55370f8
to
1905607
Compare
Any further thoughts on this? I am tempted to rip the |
MNT: unify code path of set, update, setp
Single code path for the property -> setter lookup logic.
attn @mdboom