tikzplotlib
tikzplotlib copied to clipboard
Clean Figure: Handle case if all data is nan
trafficstars
I noticed a bug in _remove_NaNs.
the faulty code:
id_nan = np.any(np.isnan(data), axis=1)
(....)
id_first = np.argwhere(np.logical_not(id_nan))[0]
I have a plot where data is array([[nan, nan]], dtype=float32), which results in np.argwhere(np.logical_not(id_nan)) returning array([], shape=(0, 1), dtype=int64). Therefore taking np.argwhere(np.logical_not(id_nan))[0] results in an index out of bounds exception (there is no first index).
This fixes the problem.
@LeanderK would be great if you could add a test case for the bug (i.e., set up a minimal example with nan data, which would fail with the released code but works with this patch applied).