FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Allow unhashable keys in AxesStack. by anntzer · Pull Request #8451 · matplotlib/matplotlib · GitHub

Repository navigation

Allow unhashable keys in AxesStack. - #8451

Merged
tacaswell merged 1 commit into
matplotlib:masterfrom
anntzer:unhashable-keys-in-axesstack
Jul 11, 2017
Merged

tacaswell merged 1 commit into
matplotlib:masterfrom
anntzer:unhashable-keys-in-axesstack

Conversation

anntzer commented Apr 9, 2017 •
edited
Loading

Copy link
Copy Markdown
Contributor

They simply will compare unequal to anything else.

Closes #8395.
Alternative to #8399 (although the part about removing Transform.__eq__ in #8399 stays valid).
See discussion starting at #7377 (comment) for why this is a reasonable approach.

Comment thread lib/matplotlib/figure.py Outdated
try:
hash(key)
except TypeError:
raise ValueError("first argument, %s, is not a valid key" % key)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

But if the same key comes in again it will get a different object which sort of defeats the point of this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

But transforms are explicitly mutable (not just by fiddling with the attributes: they actually expose a bunch of methods explicitly for that purpose), which means that trying to key on them is bound to give wrong results (this is the same reason why lists are not hashable in python). (In fact I had prepared another PR for making all transform classes hashable, but that is not a robust solution in the presence of mutability.)

I argued in #7377 that this behavior (trying to detect and drop duplicates axes) is already brittle anyways and should be deprecated.

WeatherGod commented Apr 10, 2017 via email

Copy link
Copy Markdown
Member

anntzer commented Apr 10, 2017

Copy link
Copy Markdown
Contributor Author

Freezing a transform doesn't make it immutable, it just makes it independent of changes to its children (by recursively replacing the children by "private" copies of them). This is in fact the goal stated in the docstring:

        Returns a frozen copy of this transform node.  The frozen copy
        will not update when its children change.  Useful for storing
        a previously known state of a transform where
        ``copy.deepcopy()`` might normally be used.

WeatherGod commented Apr 10, 2017 via email

Copy link
Copy Markdown
Member

anntzer commented Apr 10, 2017

Copy link
Copy Markdown
Contributor Author

Transforms are not hashable and typically not used as keys in AxesStack.

WeatherGod commented Apr 10, 2017 via email

Copy link
Copy Markdown
Member

tacaswell added this to the 2.0.1 (next bug fix release) milestone Apr 12, 2017

Copy link
Copy Markdown
Member

Ok, that makes sense, but this still seems hackish. Would in be better to remove the transform from the kwargs used to make the key (in Figure._make_key)?

On reading the code of the OP, does transform even get used? If an Axes is passed in, kwargs is only used for the key and nothing else. This seems not quite right.

anntzer commented Apr 12, 2017

Copy link
Copy Markdown
Contributor Author

FWIW I still think the ultimately correct way to do this is to get rid of the brittle "check whether there is already an axes with the same key" approach (for reasons already explained elsewhere).

Alternatively, instead of using a dict, you could just use a list of pairs (key, value) and check for equality with the keys one at a time -- there is no way you can have so many Axes that the performance becomes an issue. But this is still bound to have problematic semantics due to key mutability.

QuLogic modified the milestones: 2.0.1 (next bug fix release), 2.0.2 (next bug fix release) May 3, 2017

Copy link
Copy Markdown
Member

@anntzer I am convinced on this, can you rebase?

They simply will compare unequal to anything else.
anntzer force-pushed the unhashable-keys-in-axesstack branch from c4e83b4 to 3d6c9c0 Compare July 10, 2017 23:53

anntzer commented Jul 10, 2017

Copy link
Copy Markdown
Contributor Author

done

tacaswell merged commit f5f3d79 into matplotlib:master Jul 11, 2017

Copy link
Copy Markdown
Member

Thank you @anntzer

QuLogic modified the milestones: 2.1 (next point release), 2.0.3 (next bug fix release) Jul 11, 2017
anntzer deleted the unhashable-keys-in-axesstack branch July 11, 2017 03:11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL