Multiple boolean filters to same view

I could use direction on how to apply multiple filters to a view in cdsview

The following functions as a single source data point, however I’m looking to apply a second filter and second source data point.

    booleans = [True if y_val > float(LowerFilter.value) and y_val < float(UpperFilter.value) else False for y_val in[FilterSelect.value]]
    view = CDSView(source=source, filters=[BooleanFilter(booleans)])

The second filter would look like this in single filter application

    booleans = [True if y_val > float(LowerFilter2.value) and y_val < float(UpperFilter2.value) else False for y_val in[FilterSelect2.value]]
    view = CDSView(source=source, filters=[BooleanFilter(booleans)])

How do I combine them into a single view?

There were changes to filtering for Bokeh 3.0 please specify what version you are using/targeting.

I am currently on 2.4.3.
But, if you can kindly indicate what the formate for the latest version would also be I would be very thankful.

Bokeh 3.0 changed to only allow configuration of a single filter at a time, rather than a list of filters. Supporting list of filters was just too fragile and difficult to maintain. Per the docs:

filters can be combined with standard Python boolean operators. So, presumably something like:

cds_view.filter = BooleanFilter(booleans)

# later
cds_view.filter &= BooleanFilter(more_booleans)

I say “presumably” because, without a complete Minimal Reproducible Example to actually try out and run, the best I can do for you is point at relevant documentation and speculate.

For Bokeh 2.4.3 you should just be able to append the new filter to the existing list of filters. Or you can logical-and the lists of bool values together manually, and then set the booleans property of the existing filter to this new and’ed list.

Edit: note also for version 3.0, views no longer have a source property.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.