Skip to content

enh: Support selector and ds.summary for geom_aggregator#6743

Merged
hoxbro merged 11 commits into
mainfrom
enh_support_selector_for_geom_aggregate
Dec 17, 2025
Merged

enh: Support selector and ds.summary for geom_aggregator#6743
hoxbro merged 11 commits into
mainfrom
enh_support_selector_for_geom_aggregate

Conversation

@hoxbro

@hoxbro hoxbro commented Nov 24, 2025

Copy link
Copy Markdown
Member

Resolves #6736
Resolves #6739

Mostly factoring out logic in aggregate to also use for geom_aggregate. Not sure if I like the new method name, but just wanted to push this before it was lost in a stash. Know at least one test is failing because of change of NdOverlay to ImageStack.

Also fixes a bug where __index__ data was not sent to the frontend when hover_tooltips were used, so it would not hide tooltips.

And handle ds.by cases like what has been done aggregate.

Summary

import datashader as ds

import holoviews as hv
from holoviews.operation.datashader import rasterize

hv.extension("bokeh")

rects = hv.Rectangles(
    [
        (0, 0, 1, 1, 128, 100, 200),
        (2, 3, 4, 6, 100, 50, 80),
        (0.5, 2, 1.5, 4, 20, 200, 120),
        (2, 1, 3.5, 2.5, 110, 40, 240),
    ],
    kdims=[
        hv.Dimension("x0"),
        hv.Dimension("y0"),
        hv.Dimension("x1"),
        hv.Dimension("y1"),
    ],
    vdims=[
        hv.Dimension("r"),
        hv.Dimension("g"),
        hv.Dimension("b"),
    ],
)
rasterize(
    rects,
    aggregator=ds.summary(
        r=ds.where(ds.max("x0"), "r"),
        g=ds.where(ds.max("x0"), "g"),
        b=ds.where(ds.max("x0"), "b"),
    ),
).opts(tools=["hover"])

Screencast.From.2025-11-24.19-06-59.mp4
Selector

import datashader as ds
import numpy as np
import pandas as pd

import holoviews as hv
from holoviews.operation.datashader import datashade, dynspread, rasterize

hv.extension("bokeh")

# Set default hover tools on various plot types
hv.opts.defaults(tools=["hover"])

rects = hv.Rectangles(
    [(0, 0, 1, 1), (2, 3, 4, 6), (0.5, 2, 1.5, 4), (2, 1, 3.5, 2.5)],
    kdims=[
        hv.Dimension("Time"),
        hv.Dimension("y0"),
        hv.Dimension("x1"),
        hv.Dimension("y1"),
    ],
)

rects = datashade(rects, aggregator=ds.count(), selector=ds.min("Time"))
rects.opts(hover_tooltips=["Time"])
rects

Screencast.From.2025-11-24.19-07-53.mp4
Simple

import datashader as ds

import holoviews as hv
from holoviews.operation.datashader import rasterize

hv.extension("bokeh")

rects = hv.Rectangles(
    [
        (0, 0, 1, 1, 128, 100, 200),
        (2, 3, 4, 6, 100, 50, 80),
        (0.5, 2, 1.5, 4, 20, 200, 120),
        (2, 1, 3.5, 2.5, 110, 40, 240),
    ],
    kdims=[
        hv.Dimension("x0"),
        hv.Dimension("y0"),
        hv.Dimension("x1"),
        hv.Dimension("y1"),
    ],
    vdims=[
        hv.Dimension("r"),
        hv.Dimension("g"),
        hv.Dimension("b"),
    ],
)
rasterize(rects, aggregator=ds.max("x0")).opts(tools=["hover"])

Screencast.From.2025-11-24.19-08-25.mp4

@hoxbro hoxbro changed the title enh: Support selector for geom_aggregator enh: Support selector and ds.summary for geom_aggregator Nov 24, 2025
@codecov

codecov Bot commented Nov 24, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.94521% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.11%. Comparing base (1f0d3cf) to head (0fbc2b0).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
holoviews/operation/datashader.py 97.19% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #6743       +/-   ##
===========================================
+ Coverage   21.18%   89.11%   +67.92%     
===========================================
  Files         335      341        +6     
  Lines       72706    73241      +535     
===========================================
+ Hits        15404    65268    +49864     
+ Misses      57302     7973    -49329     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment on lines +845 to +848
if agg_state == AggState.AGG_BY:
params['vdims'] = list(map(str, agg.coords[agg_fn.column].data))
elif agg_state == AggState.AGG_SEL_BY:
params['vdims'] = [d for d in agg.data_vars if d not in agg.attrs["selector_columns"]]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is duplicated, but I think it is OK.

@hoxbro
hoxbro force-pushed the enh_support_selector_for_geom_aggregate branch from f80227a to c7d6e9b Compare November 26, 2025 11:08
@hoxbro
hoxbro force-pushed the enh_support_selector_for_geom_aggregate branch from b46191b to 54936b9 Compare November 27, 2025 09:37
@hoxbro
hoxbro force-pushed the enh_support_selector_for_geom_aggregate branch from 54936b9 to e259826 Compare November 27, 2025 09:37
@hoxbro
hoxbro marked this pull request as ready for review November 27, 2025 09:52
@hoxbro
hoxbro requested a review from philippjfr November 28, 2025 08:39
Comment thread holoviews/operation/datashader.py Outdated
Comment thread holoviews/operation/datashader.py
@philippjfr

Copy link
Copy Markdown
Member

Let's merge after the patch release.

@hoxbro hoxbro added this to the 1.23.0 milestone Dec 5, 2025
@hoxbro
hoxbro merged commit 9669127 into main Dec 17, 2025
17 checks passed
@hoxbro
hoxbro deleted the enh_support_selector_for_geom_aggregate branch December 17, 2025 13:43
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Mar 31, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rasterize() does not work with ds.summary() hover_tooltips does broken on datashader Rectangles

2 participants