Skip to content

fix: allow array-like fill_between where masks#31898

Merged
scottshambaugh merged 2 commits into
matplotlib:mainfrom
cyphercodes:fix-fill-between-where-typing
Jun 18, 2026
Merged

fix: allow array-like fill_between where masks#31898
scottshambaugh merged 2 commits into
matplotlib:mainfrom
cyphercodes:fix-fill-between-where-typing

Conversation

@cyphercodes

Copy link
Copy Markdown
Contributor

PR summary

Axes.fill_between and Axes.fill_betweenx already accept NumPy boolean masks for where at runtime, but their stubs only allowed Sequence[bool]. This widens the where annotation to ArrayLike, matching the rest of the input arrays and avoiding false-positive type checker errors for np.ndarray masks.

Fixes #31890.

AI assistance was used to prepare this patch.

PR checklist

  • The changes are tested and documented.
  • The issue is referenced.

Testing

  • PYTHONPATH=lib pyright /tmp/mpl_fill_between_pyright.py
  • python -m compileall -q lib/matplotlib/axes/_axes.pyi
  • git diff --check

@timhoffm timhoffm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we loose the bool typing, we certainly want to accept arrays. So widening is reasonable.

@cyphercodes

Copy link
Copy Markdown
Contributor Author

Updated the generated pyplot.py boilerplate so it matches the fill_between / fill_betweenx typing change in _axes.pyi.

Verification:

  • python tools/boilerplate.py
  • python -m pytest lib/matplotlib/tests/test_pyplot.py::test_pyplot_up_to_date -q
  • git diff --check

I also inspected the broader failing CI logs. The remaining GitHub/Azure matrix failures I saw are in lib/matplotlib/tests/test_mlab.py::TestSpectral / environment paths, not this PR’s touched typing/boilerplate surface.

@scottshambaugh scottshambaugh merged commit 15a8b99 into matplotlib:main Jun 18, 2026
39 of 41 checks passed
@scottshambaugh scottshambaugh added this to the v3.11.1 milestone Jun 18, 2026
@QuLogic

QuLogic commented Jun 18, 2026

Copy link
Copy Markdown
Member

@meeseeksdev backport to v3.11.x

timhoffm added a commit that referenced this pull request Jun 18, 2026
…898-on-v3.11.x

Backport PR #31898 on branch v3.11.x (fix: allow array-like fill_between where masks)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Type hints for where argument in ax.fill_between does not allow np.ndarrays

4 participants