Skip to content

FIX: ValueError when hexbin is run with empty arrays and log scaling. #23944

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 3 commits into from
Sep 23, 2022

Conversation

erykoff
Copy link
Contributor

@erykoff erykoff commented Sep 19, 2022

PR Summary

PR Checklist

Tests and Styling

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • New features are documented, with examples if plot related.
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).

@erykoff
Copy link
Contributor Author

erykoff commented Sep 19, 2022

This PR addresses #23922

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a while, please feel free to ping @matplotlib/developers or anyone who has commented on the PR. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join us on gitter for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide

We strive to be a welcoming and open project. Please follow our Code of Conduct.

@tacaswell tacaswell added this to the v3.6.1 milestone Sep 19, 2022
self.vmax = A.max()
# Ensure that A has non-zero size to compute min/max.
# Otherwise put in filler values.
if A.size:
Copy link
Member

Choose a reason for hiding this comment

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

This is hitting alot of use cases as all of the color mappables to through here, would it be possible to do this check in hexbin instead?

If we do this here, do we want to use the same logic from the auto limit on the Axis to sure min != max (which I forsee causing divide by 0 errors later)?

self.vmax = A.max()
else:
self.vmin = 0.0
self.vmax = 0.0
Copy link
Contributor

@anntzer anntzer Sep 19, 2022

Choose a reason for hiding this comment

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

Setting these values to zero seems almost certainly wrong; the pre-#21989 behavior was (I think?) to set them to np.ma.masked (I think?) which also seems a bit strange but already better.

@erykoff
Copy link
Contributor Author

erykoff commented Sep 19, 2022

Please take a look now. I pushed the fix further upstream and also used masked instead of 0.0. Maybe you have some more elegant ideas; however, this does fix the problem and pass the additional test without touching non-hexbin optimized code paths.

Copy link
Member

@dstansby dstansby left a comment

Choose a reason for hiding this comment

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

Looks good to me - thanks for the PR!

@timhoffm timhoffm merged commit 0636b9e into matplotlib:main Sep 23, 2022
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Sep 23, 2022
@timhoffm
Copy link
Member

Thanks @erykoff and congratulations on your first contribution to Matplotlib.

QuLogic added a commit that referenced this pull request Sep 23, 2022
…944-on-v3.6.x

Backport PR #23944 on branch v3.6.x (FIX: ValueError when hexbin is run with empty arrays and log scaling.)
melissawm pushed a commit to melissawm/matplotlib that referenced this pull request Dec 19, 2022
…matplotlib#23944)

* Add test for empty hexbin with log scaling.

* Use guarded autoscale_None for use when vmin/vmax are None.

* Add additional check when auto vmin/vmax are None.
@ksunden ksunden mentioned this pull request Feb 20, 2023
6 tasks
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.

5 participants