holoviz/datashader

Bug in summary reduction using multiple where reductions with the same selector

ianthomas23 opened this issue · 0 comments

Using a summary reduction containing multiple where reductions that use the same selector gives an error. Code to reproduce:

import datashader as ds
import pandas as pd

df = pd.DataFrame(dict(x=[0, 1], y=[0, 1], value=[0, 1], other=[1, 0]))

reduction = ds.summary(
    name1=ds.where(ds.max("value"), "other"),
    name2=ds.where(ds.max("value")),
)

canvas = ds.Canvas(plot_height=3, plot_width=3)
agg = canvas.points(source=df, x="x", y="y", agg=reduction)

Error produced is

  File "/Users/iant/github/datashader/datashader/compiler.py", line 137, in compile_components
    append, any_uses_cuda_mutex = make_append(bases, cols, calls, glyph, antialias)
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/iant/github/datashader/datashader/compiler.py", line 415, in make_append
    exec(code, namespace)
  File "<string>", line 4
    _10 =     _7(x, y, _1, _4[i0], _8)
    ^
IndentationError: expected an indented block after 'if' statement on line 3

The cause of the error is the ds.max("value") which is used in both where reductions and only needs to be calculated once, but its reuse in the second where is not correct.