Possible Issue with Bokeh rendering colors

I have had a very simple color effect for my bokeh glyphs and it has worked for months, I come into work today and all of a sudden my bokeh is not rendering. I check the browser developer console and see this:

bokeh.min.js?v=887e6bace8d80f5c1555c1913f730061c2d73acb83adb7f4ccf2ef02ffc7e5e864f7b1c97db9a4f6643a1431700d65e2686759f5c4bb1ac92631e8b659ceead3:164 Error rendering Bokeh items: Error: invalid color array
    at pe.v_materialize (bokeh.min.js?v=887e6bace8d80f5c1555c1913f730061c2d73acb83adb7f4ccf2ef02ffc7e5e864f7b1c97db9a4f6643a1431700d65e2686759f5c4bb1ac92631e8b659ceead3:184:10821)
    at pe.uniform (bokeh.min.js?v=887e6bace8d80f5c1555c1913f730061c2d73acb83adb7f4ccf2ef02ffc7e5e864f7b1c97db9a4f6643a1431700d65e2686759f5c4bb1ac92631e8b659ceead3:184:5664)
    at p.set_visuals (bokeh.min.js?v=887e6bace8d80f5c1555c1913f730061c2d73acb83adb7f4ccf2ef02ffc7e5e864f7b1c97db9a4f6643a1431700d65e2686759f5c4bb1ac92631e8b659ceead3:384:4086)
    at k.set_visuals (bokeh.min.js?v=887e6bace8d80f5c1555c1913f730061c2d73acb83adb7f4ccf2ef02ffc7e5e864f7b1c97db9a4f6643a1431700d65e2686759f5c4bb1ac92631e8b659ceead3:380:4705)
    at k.set_data (bokeh.min.js?v=887e6bace8d80f5c1555c1913f730061c2d73acb83adb7f4ccf2ef02ffc7e5e864f7b1c97db9a4f6643a1431700d65e2686759f5c4bb1ac92631e8b659ceead3:380:4402)
    at async k.lazy_initialize (bokeh.min.js?v=887e6bace8d80f5c1555c1913f730061c2d73acb83adb7f4ccf2ef02ffc7e5e864f7b1c97db9a4f6643a1431700d65e2686759f5c4bb1ac92631e8b659ceead3:380:1795)
    at async l (bokeh.min.js?v=887e6bace8d80f5c1555c1913f730061c2d73acb83adb7f4ccf2ef02ffc7e5e864f7b1c97db9a4f6643a1431700d65e2686759f5c4bb1ac92631e8b659ceead3:222:180)
    at async t.build_views (bokeh.min.js?v=887e6bace8d80f5c1555c1913f730061c2d73acb83adb7f4ccf2ef02ffc7e5e864f7b1c97db9a4f6643a1431700d65e2686759f5c4bb1ac92631e8b659ceead3:222:595)
    at async l.build_renderer_views (bokeh.min.js?v=887e6bace8d80f5c1555c1913f730061c2d73acb83adb7f4ccf2ef02ffc7e5e864f7b1c97db9a4f6643a1431700d65e2686759f5c4bb1ac92631e8b659ceead3:610:11060)
    at async l.lazy_initialize (bokeh.min.js?v=887e6bace8d80f5c1555c1913f730061c2d73acb83adb7f4ccf2ef02ffc7e5e864f7b1c97db9a4f6643a1431700d65e2686759f5c4bb1ac92631e8b659ceead3:610:4667)

This is telling me I have an invalid color array, which is very odd because I have triple checked these and they are all fine. I ran my code and there are no Nan values or errors appearing in the code, it is just failing when it finally lands in the bokeh server to render. Here are the colors I am using and the function creating colors for my glyphs:

```def get_color(x, max_blocks):
        # Define color ranges
        blue_shades = ['#0033FF', '#0066FF', '#0099FF', '#00CCFF']
        # Overflow colors transitioning from yellow to orange to red
        overflow_colors = [
            '#FFFF00', '#FFEE00', '#FFDD00', '#FFCC00',
            '#FFBB00', '#FFAA00', '#FF9900', '#FF8800',
            '#FF7700', '#FF6600', '#FF5500', '#FF4400',
            '#FF3300', '#FF2200', '#FF1100', '#FF0000'
        underflow_color = '#808080'  # For zero blocks

        if x == 0:
            return underflow_color
        elif x <= max_blocks:
            # Map x to the appropriate blue shade
            color_index = max(0, min(int(len(blue_shades) * x / max_blocks) - 1, len(blue_shades) - 1))
            return blue_shades[color_index]
            # Dynamically scale the overflow index based on x exceeding max_blocks
            overflow_range = max(x - max_blocks, 1)
            # Find the ratio of the current block count over the max block count within the overflow range
            ratio = (overflow_range - 1) / (28 - max_blocks) if max_blocks < 28 else 0
            overflow_index = int(ratio * (len(overflow_colors) - 1))
            return overflow_colors[min(overflow_index, len(overflow_colors) - 1)]

    # Test different values of x and max_blocks
    for x in range(0, 30, 5):
        print(f"x = {x}, color = {get_color(x, 10)}")

    for x in range(0, 30, 5):
        print(f"x = {x}, color = {get_color(x, 20)}")```

This function could return valid colors but possibly you are sending them as scalars instead of arrays, or array with an unexpected shape, or something else. Unfortunately it’s not really possible to speculate in any detail at all without a complete Minimal Reproducible Example to run and investigate directly.

Edit: looking at the codepath in question it does point to the problem being with whatever array you are creating, and not with the individual color values.

well it took nearly all day, but I found the bug. I was accidentally overwriting my columndatasource with an empty df.

I was told by my engineers that the event of all variables being true was not going to happen, well it did. which means my datasource had no data in it because of this line of code:
ballast_filtered_df = ballast_df[ballast_df[‘has_anchor’] == False]

So, no issue with the color mapper, just that one out of 20 different solutions happened to be all True. I do find it odd though that the bug called out in the console was the color array, as opposed to something like “empty Column Data Source” which probably would have been more helpful.

Still I learned alot today hunting the bug down. Thanks for being so responsive Bryan!


as opposed to something like “empty Column Data Source”

That’s not an error condition, since there are valid reasons to have empty data sources in certain cases.

1 Like