Skip to content

Fix FancyArrow rendering for zero-length arrows #30243

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

Merged
merged 6 commits into from
Jul 3, 2025

Conversation

nrnavaneet
Copy link
Contributor

Fixes #30242: Cannot create empty FancyArrow (expired NumPy deprecation).

Summary of changes:
• Addresses a bug where FancyArrow(length=0) caused issues due to expired NumPy behavior.
• Adds an explicit check for zero length to safely initialize self.verts as an empty array.
• Adds a test case test_empty_fancyarrow in test_patches.py to confirm correct behavior for zero-length arrows.

This change ensures that FancyArrow gracefully handles length=0 without triggering errors or deprecated behavior in newer NumPy versions.

@nrnavaneet nrnavaneet force-pushed the fix-fancyarrow-empty branch from ad9c92b to 070837b Compare July 2, 2025 02:03
@nrnavaneet
Copy link
Contributor Author

This PR only affects FancyArrow behavior when length == 0 and adds a test for it. The CI failures in docs/AppVeyor are unrelated and seem to be happening globally. Pre-commit passes locally.

@@ -1538,7 +1538,7 @@ def _make_verts(self):
length = distance
else:
length = distance + head_length
if not length:
if (isinstance(length, np.ndarray) and length.size == 0) or (not length):
Copy link
Member

Choose a reason for hiding this comment

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

You can use np.size here.

@nrnavaneet
Copy link
Contributor Author

Thank you for the review, @QuLogic! 🙌
I’ve updated the condition to use np.size(length) as suggested, and also removed the .python-version file from the commit. Everything should be good now. Please let me know if anything else needs changes. 😊

@QuLogic QuLogic added this to the v3.10.4 milestone Jul 3, 2025
@QuLogic QuLogic merged commit 70d5ad4 into matplotlib:main Jul 3, 2025
37 of 40 checks passed
@QuLogic
Copy link
Member

QuLogic commented Jul 3, 2025

Thanks @nrnavaneet! Congratulations on your first PR to Matplotlib 🎉 We hope to hear from you again.

Copy link

lumberbot-app bot commented Jul 3, 2025

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
git checkout v3.10.x
git pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
git cherry-pick -x -m1 70d5ad48fc26045739d5c57538686f7619cfa8bb
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
git commit -am 'Backport PR #30243: Fix FancyArrow rendering for zero-length arrows'
  1. Push to a named branch:
git push YOURFORK v3.10.x:auto-backport-of-pr-30243-on-v3.10.x
  1. Create a PR against branch v3.10.x, I would have named this PR:

"Backport PR #30243 on branch v3.10.x (Fix FancyArrow rendering for zero-length arrows)"

And apply the correct labels and milestones.

Congratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon!

Remember to remove the Still Needs Manual Backport label once the PR gets merged.

If these instructions are inaccurate, feel free to suggest an improvement.

QuLogic pushed a commit to QuLogic/matplotlib that referenced this pull request Jul 3, 2025
QuLogic pushed a commit to QuLogic/matplotlib that referenced this pull request Jul 3, 2025
jkseppan added a commit that referenced this pull request Jul 4, 2025
…3.10.x

Backport PR #30243 on branch v3.10.x (Fix FancyArrow rendering for zero-length arrows)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Cannot create empty FancyArrow (expired numpy deprecation)
3 participants