Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow and handle non-parameters in rasterize.instance() #5811

Merged
merged 5 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions holoviews/operation/datashader.py
Original file line number Diff line number Diff line change
Expand Up @@ -1388,6 +1388,7 @@ def _process(self, element, key=None):
all_supplied_kws = set()
instance_params = {
k: getattr(self, k) for k in self.__instance_params
if hasattr(self, k)
}
for predicate, transform in self._transforms:
merged_param_values = dict(instance_params, **self.p)
Expand Down
22 changes: 21 additions & 1 deletion holoviews/tests/operation/test_datashader.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
from holoviews import (
Dimension, Curve, Points, Image, Dataset, RGB, Path, Graph, TriMesh,
QuadMesh, NdOverlay, Contours, Spikes, Spread, Area, Rectangles,
Segments, Polygons, Nodes
Segments, Polygons, Nodes, DynamicMap, Overlay
)
from holoviews.util import render
from holoviews.streams import Tap
from holoviews.element.comparison import ComparisonTestCase
from numpy import nan
from holoviews.operation import apply_when
from packaging.version import Version

try:
Expand Down Expand Up @@ -1169,6 +1171,24 @@ def test_rasterize_image_expand_default(self):
output = img.data["z"].to_numpy()
assert np.isnan(output).any()

def test_rasterize_apply_when_instance_with_line_width(self):
df = pd.DataFrame(
ahuang11 marked this conversation as resolved.
Show resolved Hide resolved
np.random.multivariate_normal(
(0, 0), [[0.1, 0.1], [0.1, 1.0]], (500000,))
)
df.columns = ["a", "b"]

curve = Curve(df, kdims=["a"], vdims=["b"])
custom_rasterize = rasterize.instance(line_width=2)
ahuang11 marked this conversation as resolved.
Show resolved Hide resolved
output = apply_when(
curve, operation=custom_rasterize, predicate=lambda x: len(x) > 1000
)
render(output, "bokeh")
assert isinstance(output, DynamicMap)
overlay = output.items()[0][1]
assert isinstance(overlay, Overlay)
assert len(overlay) == 2

class DatashaderSpreadTests(ComparisonTestCase):

def test_spread_rgb_1px(self):
Expand Down