Skip to content

fix: allow array-like fill_between where masks#31898

Open
cyphercodes wants to merge 2 commits into
matplotlib:mainfrom
cyphercodes:fix-fill-between-where-typing
Open

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

Conversation

@cyphercodes

Copy link
Copy Markdown

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
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.

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

2 participants