-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
plt.contour with all NaNs fails assertion in _contour.cpp #14124
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
@ianthomas23 would you like to look at this? It sounds like maybe more early-stage argument checking is needed. |
The assertions in The C++ assertion is a distraction here, although it did help to identify the problem. For an array of NaNs there is no point in ever accessing the C++ contouring code as there are no contours to find. A better approach would be for the python code ( There is a question of policy here. When trying to contour an array of NaNs, do we (1) report a warning and return a valid but empty contour set, or (2) raise an exception instead? |
I think the prevailing policy, and a good one, is to return empty but valid objects, like this:
|
The current behavior as of master is to spit out a lot of warnings, but actually draw the figure (original example from above):
So, basically as desired. However the number of warnings could be reduced. Implementing just one warning will be cumbersome. Either you follow the original code path but prevent all the above warnings when they occur. Or you break early, but then you have to make sure, you still get a valid |
Now there are fewer warnings:
Probably few enough to add a smoke test so that it doesn't break again and close this issue. |
Marking as good first issue as it is only to create a test (using the original code above) that catches the warnings. Not sure how the catch-and-match-logic behaves with three warnings though. Make sure to add a comment like:
in the test. |
Bug report
Bug summary
Passing an array with all NaN values into
pyplot.contour()
causes the following assertion to fail inQuadContourGenerator::init_cache_levels
:https://github.com/matplotlib/matplotlib/blob/v3.0.3/src/_contour.cpp#L1317-L1318
This is actually triggered by a test-case in the xarray test suite, but I imagine it hasn't been noticed (yet) because release builds of matplotlib typically disable assertion checks.
Code for reproduction
Actual outcome
Failed assertion (see referenced line above, tracked down with
gdb
)Expected outcome
I would expect to see the empty plot (and long lists of warnings) that are currently shown if assertions are disabled:

Matplotlib version
print(matplotlib.get_backend())
): aggPython, matplotlib, etc are installed from source
The text was updated successfully, but these errors were encountered: