Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

BF - prevent a TypeError for lists of vertices in set_marker #1840

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
4 participants
Contributor

ajdawson commented Mar 21, 2013

The documentation for setting markers (http://matplotlib.org/api/artist_api.html#matplotlib.lines.Line2D.set_marker) suggests that:

a list of (x, y) pairs used for Path vertices

is an acceptable input. However, if one tries to use a Python list a TypeError is returned. This is because the set_marker code attempts to use the marker specification as the key in a dictionary, which fails because lists are not hashable. To avoid this I added an extra condition to the logic that makes sure the input is not a list before attempting to use it as a dictionary key (taking advantage of lazily evaluated boolean conditions). This allows the final conditional to be executed which happily constructs a path from a list of vertices, just as it does from a tuple of vertices.

Member

pelson commented Mar 21, 2013

Thanks @ajdawson - would you be able to add a test? (updating an existing test, if appropriate, would be fine)

Contributor

ajdawson commented Mar 21, 2013

I added a new test in test_axes.py, it seemed the most appropriate option.

Contributor

ajdawson commented Mar 21, 2013

OK I've used extensions=['png'] and removed the pdf and svg test images. I overwrote the test image with one that contains no text without thinking about it. The test function is written so that it would produce text, but has remove_text=True in the image comparison decorator, so I guess this is OK?

Member

dmcdougall commented Mar 23, 2013

In my opinion, this is fixing a bug and should target v1.2.x. What do others think?

Owner

efiring commented Mar 23, 2013

Yes, it is fixing a bug.

Contributor

ajdawson commented Mar 24, 2013

I made a new PR #1854 that introduces this change into the v1.2.x branch.

@ajdawson ajdawson closed this Mar 24, 2013

@ajdawson ajdawson deleted the ajdawson:fix-marker-list branch Jul 18, 2013

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