Skip to content
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

colors: ensure masked array data is an ndarray #6622

Merged
merged 2 commits into from Jun 22, 2016

Conversation

ngoldbaum
Copy link
Contributor

This fixes compatibility for imshow plots with array data that is a unit-aware ndarray subclass, for example data from yt.units or astropy.units.

Take for example the following script:

import numpy as np
import matplotlib.pyplot as plt
from yt.units import km

arr = np.random.random((400, 400))*km

plt.imshow(a)
plt.show()

This produces the following traceback right now: https://gist.github.com/ngoldbaum/27effb41173859132fed08a0ad5485ee

This is not isolated to yt's units - if one tries the same thing with astropy's units the same issue arises. Pint does not have this issue because Pint's Quantity class is not an ndarray subclass, so when it is converted to a masked array in matplotlib.image, the units are stripped.

This function seems to expect result.data to be an instance of the base ndarray class. This patch just enforces that expectation explicitly.

This fixes compatibility for imshow plots with array data that is a unit-aware
ndarray subclass, for example data frmo yt.units or astropy.units.
@ngoldbaum
Copy link
Contributor Author

Hmm... that failure on travis is worrying. Let me see if I can reproduce it...

@ngoldbaum
Copy link
Contributor Author

Can't reproduce that failure locally...

@jenshnielsen
Copy link
Member

Travis failures are transient and non related

@efiring
Copy link
Member

efiring commented Jun 21, 2016

Looks OK to me, but I suggest adding a brief comment so that someone doesn't look at it a year from now and "optimize" it away, thinking it is superfluous.

@tacaswell tacaswell added this to the 2.0 (style change major release) milestone Jun 21, 2016
@tacaswell
Copy link
Member

Still not have tagged a v1.5.2, should probably backport this?

@ngoldbaum
Copy link
Contributor Author

If you can backport this for 1.5.2, that would be excellent :)

@tacaswell tacaswell merged commit f8ea2c5 into matplotlib:master Jun 22, 2016
tacaswell added a commit that referenced this pull request Jun 22, 2016
FIX: ensure masked array data is an ndarray
@tacaswell
Copy link
Member

backported to 1.5.x as 8d9357e

@tacaswell
Copy link
Member

Backported as it fixes a major Yt headache

@QuLogic QuLogic modified the milestones: 1.5.2 (Critical bug fix release), 2.0 (style change major release) Jun 23, 2016
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.

None yet

6 participants