holoviz / datashader

Quickly and accurately render even the largest data.
http://datashader.org
BSD 3-Clause "New" or "Revised" License
3.24k stars 363 forks source link

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

Closed ianthomas23 closed 10 months ago

ianthomas23 commented 10 months ago

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.