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
[Bug]: fill_between gives IndexError with numpy 1.24.0.dev #24106
Comments
This seems to be due to a change in how masked arrays work in numpy. Under some condition we are getting masks which are a single bool rather than an array of bools. Looking at
which means that we pass a bool into
which also fails on older versions of numpy (which seems both reasonable and correct). That is far as made it debugging this. Not sure if this is a regression upstream in numpy we should report or if this is intentional change we need to adapt to. @melissawm as our local numpy dev. |
This bisects to numpy/numpy@44c8da9, which coincidentally fixes numpy/numpy#19332 which is a bug I reported. The |
Something like this might work? diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py
index 64ee4a5122..cd18072fe4 100644
--- a/lib/matplotlib/axes/_axes.py
+++ b/lib/matplotlib/axes/_axes.py
@@ -5274,8 +5274,8 @@ default: :rc:`scatter.edgecolors`
where = where & ~functools.reduce(
np.logical_or, map(np.ma.getmask, [ind, dep1, dep2]))
- ind, dep1, dep2 = np.broadcast_arrays(
- np.atleast_1d(ind), dep1, dep2, subok=True)
+ ind, dep1, dep2, where = np.broadcast_arrays(
+ np.atleast_1d(ind), dep1, dep2, where, subok=True)
polys = []
for idx0, idx1 in cbook.contiguous_regions(where): |
Or actually, since we definitely want an array here, this is probably better: diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py
index 64ee4a5122..e6d8a73689 100644
--- a/lib/matplotlib/axes/_axes.py
+++ b/lib/matplotlib/axes/_axes.py
@@ -5272,7 +5272,7 @@ default: :rc:`scatter.edgecolors`
raise ValueError(f"where size ({where.size}) does not match "
f"{ind_dir} size ({ind.size})")
where = where & ~functools.reduce(
- np.logical_or, map(np.ma.getmask, [ind, dep1, dep2]))
+ np.logical_or, map(np.ma.getmaskarray, [ind, dep1, dep2]))
ind, dep1, dep2 = np.broadcast_arrays(
np.atleast_1d(ind), dep1, dep2, subok=True) |
Thanks for the quick fix! 🙇♀️ |
README.rst to README.md .rst to .md for README .rst to .md README DOC: add API change note for colorbar deprecation added twine install and check of readme rendering Fix mask lookup in fill_between for NumPy 1.24+ Fixes matplotlib#24106 Add exception class to pytest.warns calls This is failing on current pytest. DOC: Remove overly complex examples from plot_types/3D
- noted that the plotter for frq response not working in numpy 1.24, but OK in 1.25 - seems related to this: matplotlib/matplotlib#24106
Bug summary
There is a test in
astropy
that started breaking when using matplotlib + numpy 1.24.0.dev0+896.g5ecaf36cd . Same error using stable matplotlib and matplotlib from the nightly wheel.The actual test is at https://github.com/astropy/astropy/blob/75f9b60b5521ed8dae08611ddf766c95ce421801/astropy/visualization/tests/test_units.py#L24 but I will give reproducible example without astropy below.
Example log with the astropy failure: https://github.com/astropy/astropy/actions/runs/3198205490/jobs/5222440278
Code for reproduction
Actual outcome
Expected outcome
No error.
Additional information
Only with numpy 1.24.0.dev0+896.g5ecaf36cd but not with stable numpy.
Operating system
Debian or Ubuntu
Matplotlib Version
stable or nightly
Matplotlib Backend
agg
Python version
3.10 and 3.11
Jupyter version
N/A
Installation
pip
The text was updated successfully, but these errors were encountered: