Issue 1:
Bug summary

The function ax.errorbar raises a StopIteration error when yerr contains only NaN values.

Code for reproduction

import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots(1, 1)
ax.errorbar([0], [0], [np.nan])

Actual outcome

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "~/.local/share/virtualenvs/pipeline/lib/python3.9/site-packages/matplotlib/__init__.py", line 1423, in inner
return func(ax, *map(sanitize_sequence, args), **kwargs)
File "~.local/share/virtualenvs/pipeline/lib/python3.9/site-packages/matplotlib/axes/_axes.py", line 3488, in errorbar
yerr = _upcast_err(yerr)
File "~/.local/share/virtualenvs/pipeline/lib/python3.9/site-packages/matplotlib/axes/_axes.py", line 3470, in _upcast_err
isinstance(cbook._safe_first_finite(err), np.ndarray)
File "~/.local/share/virtualenvs/pipeline/lib/python3.9/site-packages/matplotlib/cbook/__init__.py", line 1749, in _safe_first_finite
return next(val for val in obj if safe_isfinite(val))
StopIteration

Expected outcome

No crash, similar to the case where only some values are NaN.

Additional information

This happens because _upcast_err unconditionally looks for a first finite element in xerr and yerr.

Operating system

Debian

Matplotlib Version

3.6.2

Matplotlib Backend

TkAgg

Python version

3.9.2

Jupyter version

No response

Installation

pip

Issue 2:
Bug report

Bug summary

If all values passed as colors are "bad" (np.nan), a warning is thrown from numpy about converting masked values to null. If some of the values are "bad", this does not happen.

Code for reproduction

import numpy as np, matplotlib.pyplot as plt

This does not warn:

c = np.full(10, np.nan)
c[0] = 1.
plt.scatter(np.ones(10), np.ones(10), c=c)
plt.show()

This does:

plt.scatter(np.ones(10), np.ones(10), c=np.full(10, np.nan))
plt.show()

<__array_function__ internals>:5: UserWarning: Warning: converting a masked element to nan.
/usr/local/lib/python3.8/site-packages/numpy/core/_asarray.py:85: UserWarning: Warning: converting a masked element to nan.
return array(a, dtype, copy=False, order=order)

This is difficult to hide since since the warning is not thrown when the figure is being constructed, but when it is shown. Here's a full traceback to show this:

Full traceback

File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.8/site-packages/matplotlib/pyplot.py", line 337, in show
return _backend_mod.show(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/matplotlib/backend_bases.py", line 3544, in show
cls.mainloop()
File "/usr/local/lib/python3.8/site-packages/matplotlib/backends/backend_macosx.py", line 171, in mainloop
_macosx.show()
File "/usr/local/lib/python3.8/site-packages/matplotlib/backends/backend_macosx.py", line 61, in _draw
self.figure.draw(renderer)
File "/usr/local/lib/python3.8/site-packages/matplotlib/artist.py", line 41, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/matplotlib/figure.py", line 1863, in draw
mimage._draw_list_compositing_images(
File "/usr/local/lib/python3.8/site-packages/matplotlib/image.py", line 131, in _draw_list_compositing_images
a.draw(renderer)
File "/usr/local/lib/python3.8/site-packages/matplotlib/artist.py", line 41, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/matplotlib/cbook/deprecation.py", line 411, in wrapper
return func(*inner_args, **inner_kwargs)
File "/usr/local/lib/python3.8/site-packages/matplotlib/axes/_base.py", line 2748, in draw
mimage._draw_list_compositing_images(renderer, self, artists)
File "/usr/local/lib/python3.8/site-packages/matplotlib/image.py", line 131, in _draw_list_compositing_images
a.draw(renderer)
File "/usr/local/lib/python3.8/site-packages/matplotlib/artist.py", line 41, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/matplotlib/collections.py", line 931, in draw
Collection.draw(self, renderer)
File "/usr/local/lib/python3.8/site-packages/matplotlib/artist.py", line 41, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/matplotlib/collections.py", line 346, in draw
self.update_scalarmappable()
File "/usr/local/lib/python3.8/site-packages/matplotlib/collections.py", line 855, in update_scalarmappable
self._facecolors = self.to_rgba(self._A, self._alpha)
File "/usr/local/lib/python3.8/site-packages/matplotlib/cm.py", line 332, in to_rgba
x = self.norm(x)
File "/usr/local/lib/python3.8/site-packages/matplotlib/colors.py", line 1048, in __call__
(vmin,), _ = self.process_value(self.vmin)
File "/usr/local/lib/python3.8/site-packages/matplotlib/colors.py", line 1012, in process_value
dtype = np.min_scalar_type(value)
File "<__array_function__ internals>", line 5, in min_scalar_type
File "/usr/local/lib/python3.8/site-packages/numpy/ma/core.py", line 4331, in __float__
warnings.warn("Warning: converting a masked element to nan.", stacklevel=2)
File "/usr/local/Cellar/python@3.8/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/warnings.py", line 109, in _showwarnmsg
sw(msg.message, msg.category, msg.filename, msg.lineno,
File "<stdin>", line 3, in warn_with_traceback
<__array_function__ internals>:5: UserWarning: Warning: converting a masked element to nan.
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.8/site-packages/matplotlib/pyplot.py", line 337, in show
return _backend_mod.show(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/matplotlib/backend_bases.py", line 3544, in show
cls.mainloop()
File "/usr/local/lib/python3.8/site-packages/matplotlib/backends/backend_macosx.py", line 171, in mainloop
_macosx.show()
File "/usr/local/lib/python3.8/site-packages/matplotlib/backends/backend_macosx.py", line 61, in _draw
self.figure.draw(renderer)
File "/usr/local/lib/python3.8/site-packages/matplotlib/artist.py", line 41, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/matplotlib/figure.py", line 1863, in draw
mimage._draw_list_compositing_images(
File "/usr/local/lib/python3.8/site-packages/matplotlib/image.py", line 131, in _draw_list_compositing_images
a.draw(renderer)
File "/usr/local/lib/python3.8/site-packages/matplotlib/artist.py", line 41, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/matplotlib/cbook/deprecation.py", line 411, in wrapper
return func(*inner_args, **inner_kwargs)
File "/usr/local/lib/python3.8/site-packages/matplotlib/axes/_base.py", line 2748, in draw
mimage._draw_list_compositing_images(renderer, self, artists)
File "/usr/local/lib/python3.8/site-packages/matplotlib/image.py", line 131, in _draw_list_compositing_images
a.draw(renderer)
File "/usr/local/lib/python3.8/site-packages/matplotlib/artist.py", line 41, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/matplotlib/collections.py", line 931, in draw
Collection.draw(self, renderer)
File "/usr/local/lib/python3.8/site-packages/matplotlib/artist.py", line 41, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/matplotlib/collections.py", line 346, in draw
self.update_scalarmappable()
File "/usr/local/lib/python3.8/site-packages/matplotlib/collections.py", line 855, in update_scalarmappable
self._facecolors = self.to_rgba(self._A, self._alpha)
File "/usr/local/lib/python3.8/site-packages/matplotlib/cm.py", line 332, in to_rgba
x = self.norm(x)
File "/usr/local/lib/python3.8/site-packages/matplotlib/colors.py", line 1048, in __call__
(vmin,), _ = self.process_value(self.vmin)
File "/usr/local/lib/python3.8/site-packages/matplotlib/colors.py", line 1019, in process_value
data = np.asarray(value)
File "/usr/local/lib/python3.8/site-packages/numpy/core/_asarray.py", line 85, in asarray
return array(a, dtype, copy=False, order=order)
File "/usr/local/lib/python3.8/site-packages/numpy/ma/core.py", line 4331, in __float__
warnings.warn("Warning: converting a masked element to nan.", stacklevel=2)
File "/usr/local/Cellar/python@3.8/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/warnings.py", line 109, in _showwarnmsg
sw(msg.message, msg.category, msg.filename, msg.lineno,
File "<stdin>", line 3, in warn_with_traceback
/usr/local/lib/python3.8/site-packages/numpy/core/_asarray.py:85: UserWarning: Warning: converting a masked element to nan.
return array(a, dtype, copy=False, order=order)

Expected outcome

I wouldn't expect the second to warn if the first doesn't.

Matplotlib version

Operating system: macOS

Matplotlib version: 3.3.1

Matplotlib backend (print(matplotlib.get_backend())): MacOSX and module://ipykernel.pylab.backend_inline

Python version: 3.8.5

Jupyter version (if applicable): Replicates in python repl, but also was happening in ipython and jupyter lab

Other libraries:

Installed with pip