Closed 2sn closed 9 months ago
This seems a bug upstream in numpy:
np.seterr(under="raise")
x=np.arange(0, 3, 0.1)
dX = np.diff(x)
X = np.ma.array(x)
dX = np.diff(X)
dX = dX / 2.0
returns
Traceback (most recent call last):
File "/Users/jklymak/matplotlib/testit.py", line 9, in <module>
dX = dX / 2.0
~~~^~~~~
File "/Users/jklymak/mambaforge/envs/mpl-dev/lib/python3.11/site-packages/numpy/ma/core.py", line 4275, in __truediv__
return true_divide(self, other)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/jklymak/mambaforge/envs/mpl-dev/lib/python3.11/site-packages/numpy/ma/core.py", line 1171, in __call__
m |= domain(da, db)
^^^^^^^^^^^^^^
File "/Users/jklymak/mambaforge/envs/mpl-dev/lib/python3.11/site-packages/numpy/ma/core.py", line 858, in __call__
return umath.absolute(a) * self.tolerance >= umath.absolute(b)
~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
FloatingPointError: underflow encountered in multiply
Note that you need to divide by 2 to get the error.
A work around for us is to multiply by 0.5 instead.
Digging a bit more, this definitly looks like a numpy bug as the multiple that is failing is part of its internal business.
In [15]: dX / 2
---------------------------------------------------------------------------
FloatingPointError Traceback (most recent call last)
Cell In[15], line 1
----> 1 dX / 2
File /usr/lib/python3.11/site-packages/numpy/ma/core.py:4275, in MaskedArray.__truediv__(self, other)
4273 if self._delegate_binop(other):
4274 return NotImplemented
-> 4275 return true_divide(self, other)
File /usr/lib/python3.11/site-packages/numpy/ma/core.py:1171, in _DomainedBinaryOperation.__call__(self, a, b, *args, **kwargs)
1169 domain = ufunc_domain.get(self.f, None)
1170 if domain is not None:
-> 1171 m |= domain(da, db)
1172 # Take care of the scalar case first
1173 if not m.ndim:
File /usr/lib/python3.11/site-packages/numpy/ma/core.py:858, in _DomainSafeDivide.__call__(self, a, b)
856 a, b = np.asarray(a), np.asarray(b)
857 with np.errstate(invalid='ignore'):
--> 858 return umath.absolute(a) * self.tolerance >= umath.absolute(b)
FloatingPointError: underflow encountered in multiply
In [16]: %debug
> /usr/lib/python3.11/site-packages/numpy/ma/core.py(858)__call__()
856 a, b = np.asarray(a), np.asarray(b)
857 with np.errstate(invalid='ignore'):
--> 858 return umath.absolute(a) * self.tolerance >= umath.absolute(b)
859
860
ipdb> a
self = <numpy.ma.core._DomainSafeDivide object at 0x77c30803cc90>
a = array([0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1,
0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1,
0.1, 0.1, 0.1])
b = array(2)
ipdb> self.tolerance
2.2250738585072014e-308
ipdb> umath.absolute(b)
2
ipdb> umath.absolute(a)
array([0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1,
0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1,
0.1, 0.1, 0.1])
ipdb> umath.absolute(a) * self.tolerance
*** FloatingPointError: underflow encountered in multiply
ipdb> umath.absolute(a) * self.tolerance
Bug summary
When
np.seterr(under="raise")
is set, the pcolormesh fails. Maybe this should be internally disabled?Code for reproduction
Actual outcome
Expected outcome
a plot
Additional information
seems to be generic, but specific to this dataset
Operating system
Fedora 39
Matplotlib Version
3.8.2
Matplotlib Backend
GTK4Agg
Python version
3.11.8
Jupyter version
IPython 8.21.0
Installation
pip