Skip to content

[Bug]: Refactor of hexbin for 3.6.0 crashes with empty arrays and log scaling #23922

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

Closed
erykoff opened this issue Sep 17, 2022 · 5 comments
Closed

Comments

@erykoff
Copy link
Contributor

erykoff commented Sep 17, 2022

Bug summary

With 3.5 and previously, doing hexbin with empty arrays and log scaling just produced an empty plot. With 3.6.0 it crashes.

Code for reproduction

import matplotlib.pyplot as plt

plt.hexbin([], [], bins='log')

Actual outcome

...

File ~/miniforge3/envs/mpl36/lib/python3.10/site-packages/numpy/core/_methods.py:44, in _amin(a, axis, out, keepdims, initial, where)
42 def _amin(a, axis=None, out=None, keepdims=False,
43 initial=_NoValue, where=True):
---> 44 return umr_minimum(a, axis, None, out, keepdims, initial, where)

ValueError: zero-size array to reduction operation minimum which has no identity

Expected outcome

It just runs and then a plt.show() gives an empty rectangle.

Additional information

No response

Operating system

macos arm64

Matplotlib Version

3.6.0

Matplotlib Backend

MacOSX

Python version

3.10

Jupyter version

No response

Installation

conda

@greglucas
Copy link
Contributor

bisects to: #21989

@erykoff
Copy link
Contributor Author

erykoff commented Sep 18, 2022

Ah, so it seems that the change from super().autoscale(np.ma.array(A, mask=(A <= 0))) (which does produce min/max values for a fully masked array) to super().autoscale(in_trf_domain) (where in_trf_domain is a zero-length array) is the key change. I believe this would crash if log-scale is used any time all the bins are zero or negative.

I don't know what the correct solution is; is it as simple as putting a guard in autoscale like in autoscale_None that checks if A has a non-zero size? I don't know if this would have other bad downstream effects.

@tacaswell
Copy link
Member

I suspect adding that guard is the right thing to do. It is impossible to correctly autoscale with no data so it is a bit of an undefined operation. In this case doing anything is better than crashing. It would be best if we still maintained the old behavior.

@erykoff
Copy link
Contributor Author

erykoff commented Sep 18, 2022

Putting in a guard (hacking my installation and not running a full test) does work in terms of not crashing, but leaves the hexbin (in particular) with no background rather than the default bluish background. I'm not sure if this is a problem, but it is different from the previous behavior (and the behavior without log scaling), but I don't know what the default values of vmin and vmax used to be in this case.

@QuLogic
Copy link
Member

QuLogic commented Sep 23, 2022

Closed by #23944.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants