-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
plt.hist() fails with TensorFlow Numpy emulation #19574
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
Comments
I think we are happy to help, but we make no guarantee to support all numpy-like objects that exist in the python universe. If you want help with this I suggest figuring out how to reproduce w/o tensorflow so we can advise. |
This looks like a failure of the up-cast to 2D logic (and instead of 1 histogram of N elements we are seeing N histograms of 1 element). |
Specifically this code: matplotlib/lib/matplotlib/cbook/__init__.py Lines 1384 to 1444 in a510e32
which recently got re-worked due to changes in how numpy auto-up-casts object / ragged arrays. |
The Tensorflow failure is the only case I know, and it's how I ended up reporting this bug. I was just trying to learn the Numpy emulation in Tensorflow. |
I think the two problems are:
from collections.abc import Iterable
print(isinstance(labels1[0], Iterable))
print(isinstance(labels2[0], Iterable)) |
It is reasonable to expect that we will ducktype TF arrays correctly here. For now I think there is a user-space work around to cant to numpy before passing to us. That said, none of the core developers are regular TF users so any help with duck-typing them correctly would be greatly appreciated. Internally we can not directly use Labeled this as good first issue because I think all of the work that needs to be done is in |
I think it is desirable to ducktype what we can, but we need some rules for what that means. Random object |
Isn't that what |
Long term we can rely on the behavior defined by https://data-apis.org/blog/array_api_standard_release/ but for now I suspect we are going to have to keep playing whack-a-mole with these. |
As discussed on the dev call: We are happy to take a patch that improves the duck typing here, and provides a mock class that behaves like the object so that we can run tests. We cannot take downstream libraries as a test dependency (except for pandas) so someone will have to go through the effort of making a mock. In user space, please convert to a numpy array or list of lists or list of numpy arrays. Nothing else is documented or guaranteed to work. While we don't try to break things, passing other objects are not guaranteed to be stable. Downstream libraries should be able to avoid these problems by providing a
|
If |
Pushed to 3.5. I think the action items here are
|
Is this really a good first issue? |
Probably 2. can be done as a first issue. For 1. I don't think we even know what we expect. |
I think part 2 is a good first issue to Matplotlib for someone who is fluent in tensorflow and array conventions. |
Are you using the same version of tensorflow with both mpl3.4.3 and mpl3.3.4? If not, it could be that something changed on the TF side to match our expectation of what an "array" is better. If so, then maybe we accidentally fixed this and it can be closed! |
I have used mpl 3.4.3 with tensorflow 2. I haven't worked with mpl 3.3.4. It works fine with mpl 3.4.3 with tensorflow 2. |
Do you get the same results as in this comment? from collections.abc import Iterable
print(isinstance(labels1[0], Iterable))
print(isinstance(labels2[0], Iterable)) |
@mwaskom I am not sure about the idea mentioned in that comment. I just tried getting the plot with the given code and it worked fine. |
Can you try running that code in the environment where the plot works? |
I have tried running it. It works fine with mpl 3.4.3 and tensorflow 2 |
Yes but what does it print? |
See above comment https://github.com/matplotlib/matplotlib/issues/19574#issuecomment-902075023. I have attached the output I got. |
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help! |
I don't know whether this is still an issue (I think so) but something is a little whacky about this bot: it has been a lot more than 365 days since the last comment here. |
I guess if we wanted to be strict, the bot message could say "it has been over 365 days since the last update". It's basically just working through the issue backlog and checking update timestamps. |
To clarify further, we set a limit of how many issues get checked and how often so that they don't all get closed at once with no chance for comment. |
Bug report
Bug summary
Generating
np.random.randn(1000)
values, visualizing them withplt.hist()
. Works fine with Numpy.When I replace Numpy with tensorflow.experimental.numpy, Matplotlib 3.3.4 fails to display the histogram correctly. Matplotlib 3.2.2 works fine.
Code for reproduction
Actual outcome
Expected outcome
Matplotlib version
import matplotlib; print(matplotlib.__version__)
): 3.3.4print(matplotlib.get_backend())
): module://ipykernel.pylab.backend_inlineTensorFlow 2.4.1
Python installed from python.org as an exe installer. Everything else is
pip install --user
Bug opened with TensorFlow on this same issue:
tensorflow/tensorflow#46274
The text was updated successfully, but these errors were encountered: