tikzplotlib icon indicating copy to clipboard operation
tikzplotlib copied to clipboard

Clean Figure: Handle case if all data is nan

Open LeanderK opened this issue 2 years ago • 1 comments
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 avatar Feb 10 '23 17:02 LeanderK

@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).

st-- avatar May 06 '23 17:05 st--