silx
silx copied to clipboard
Warning on statshandler
No idea if it was already fixed, but here is a warning from python 3.7, and silx 1.0.0 (maybe beta)
2022-01-27 19:03:04,091 eh3 3065 py.warnings WARNING :
/.../bliss_dev/lib/python3.7/site-packages/silx/gui/plot/stats/statshandler.py:78:
FutureWarning: Format strings passed to MaskedConstant are ignored,
but in future may error or produce different behavior
return self.formatter.format(val)
From the information you provide this could come from something like a MaskedArray provided to StatsHandler.format.
On 'recent' numpy version __format__ function is redefined and raise this kind of error.
The thing is that we are calling this function to format the results which are expected to be a scalar or a tuple (or a list in fact) If the result turn out to be a masked array then we should be able to handle it by adding something like:
if isinstance(val, numpy.ma.masked_array):
val = val.compressed()
But here I wonder why the result is a masked array. That I don't think it should happen.
@vallsv Do you have more input ? Like a way to reproduce it or do you know if this log comes from the default Stats classes from silx or from a home made one ?
I managed to reproduce, this is the StatCOM that causes trouble when there is no data to compute it.
In this case, the whole array is masked and the numpy.sum returns a MaskedConstant... as well as all computations further down...
To reproduce:
from silx import sx
w = sx.plot((1, 2, 3))
w.getStatsAction().trigger()
w.getStatsWidget().setStatsOnVisibleData(True)
w.getXAxis().setLimits(-2, -1) # Move data outside of visible area
silx/gui/plot/stats/statshandler.py:78: FutureWarning: Format strings passed to MaskedConstant are ignored, but in future may error or produce different behavior
return self.formatter.format(val)
Also for any Stats initialised with a function (e.g., numpy.mean), when data is outside the plot, the function is given a fully masked array, leading to the same warning.