chaco icon indicating copy to clipboard operation
chaco copied to clipboard

Bar plots can't accept nan values.

Open scott-maddox opened this issue 6 years ago • 6 comments

Problem Description

Application crash caused by uncaught C++ exception originating from enable/kiva/agg (presumably; origin not confirmed by debug or error trace). It might be more appropriate to file this issue against enable, but I thought I would start here.

The error message:

libc++abi.dylib: terminating with uncaught exception of type std::overflow_error: Exceeded cell block limit
Abort trap: 6

Reproduction Steps:

Run the following test code.

import numpy as np

from chaco.api import ArrayPlotData, Plot
from enable.api import ComponentEditor
from traits.api import HasTraits, Instance
from traitsui.api import UItem, View


class Test(HasTraits):
    bar_plot = Instance(Plot)

    def _bar_plot_default(self):
        x = [0, 1]
        y = [np.nan, 1.0]
        plot = Plot(ArrayPlotData(x=x, y=y))
        plot.plot(('x', 'y'), type='bar')
        return plot

    traits_view = View(
        UItem('bar_plot', editor=ComponentEditor()),
    )


if __name__ == "__main__":
    Test().configure_traits()

Expected behavior:

Open a QT window with Chaco bar plot.

OS, Python version: macOS 10.14.6

$ python
Enthought Deployment Manager -- https://www.enthought.com
Python 3.6.0 |Enthought, Inc. (x86_64)| (default, Mar  3 2017, 03:26:01) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin

Package versions: traits 5.1.2-1 traitsui 6.1.1-3 chaco 4.7.2-4 enable 4.8.0-1 pyqt 4.12.1-1

scott-maddox avatar Aug 09 '19 17:08 scott-maddox

This isn't an agg issue despite that being where the error originates from, it's more that bar plots as currently implemented don't allow nan for missing values (things like line plots explicitly filter them out before plotting).

A work-around is to simply filter nans before adding to the ArrayPlotData:

mask = np.isfinite(y)
plot = Plot(ArrayPlotData(x=x[mask], y=y[mask]))

corranwebster avatar Aug 10 '19 15:08 corranwebster

Well, if passing NaNs to Agg causes a C++ exception, then it's also a kiva.agg bug that our wrapper doesn't check for NaNs and raise a Python exception.

rkern avatar Aug 10 '19 18:08 rkern

Is this something that should be handled by Chaco, or does this need to be addressed in Enable (kiva)?

jvkersch avatar Aug 17 '19 08:08 jvkersch

I feel like the new title doesn't quite capture the problem. It's not just that bar plots can't accept nan values---it's that the entire application crashes with a cryptic error message when a bar plot is given a nan value.

scott-maddox avatar Aug 19 '19 16:08 scott-maddox

enthought/enable#750 covers the C++ exception handling, but even with enthought/enable#751 in place this still crashes when the OverflowError isn't caught (even though its a Python exception now).

This only appears to be a problem with kiva.agg. celiagg gives the same rendered result as the quartz and qpainter backends.

jwiggins avatar Mar 24 '21 14:03 jwiggins