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

Only merge changed instance params with rasterize #5767

Merged
merged 5 commits into from
Jun 20, 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
14 changes: 14 additions & 0 deletions holoviews/core/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,20 @@ def isnumeric(val):
return False


def isequal(value1, value2):
"""Compare two values, returning a boolean.

Will apply the comparison to all elements of an array/dataframe.
"""
try:
check = value1 == value2
hoxbro marked this conversation as resolved.
Show resolved Hide resolved
if not isinstance(check, bool) and hasattr(check, "all"):
check = check.all()
return bool(check)
except Exception:
return False


def asarray(arraylike, strict=True):
"""
Converts arraylike objects to NumPy ndarray types. Errors if
Expand Down
8 changes: 6 additions & 2 deletions holoviews/operation/datashader.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
)
from ..core.util import (
cast_array_to_int64, cftime_types, cftime_to_timestamp,
datetime_types, dt_to_int, get_param_values
datetime_types, dt_to_int, get_param_values, isequal
)
from ..element import (Image, Path, Curve, RGB, Graph, TriMesh,
QuadMesh, Contours, Spikes, Area, Rectangles,
Expand Down Expand Up @@ -1378,8 +1378,12 @@ def _process(self, element, key=None):
# Potentially needs traverse to find element types first?
all_allowed_kws = set()
all_supplied_kws = set()
non_default_params = {
k: v for k, v in self.param.values().items()
if not isequal(v, self.param[k].default)
}
philippjfr marked this conversation as resolved.
Show resolved Hide resolved
for predicate, transform in self._transforms:
merged_param_values = dict(self.param.values(), **self.p)
merged_param_values = dict(non_default_params, **self.p)

# If aggregator or interpolation are 'default', pop parameter so
# datashader can choose the default aggregator itself
Expand Down
18 changes: 18 additions & 0 deletions holoviews/tests/operation/test_datashader.py
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,24 @@ def test_rasterize_image_string_aggregator(self):
expected = Image(([2., 7.], [0.75, 3.25], [[1, 5], [6, 22]]))
self.assertEqual(regridded, expected)

def test_rasterize_image_expand_default(self):
# Should use expand=False by default
assert not regrid.expand

data = np.arange(100.0).reshape(10, 10)
c = np.arange(10.0)
da = xr.DataArray(data, coords=dict(x=c, y=c))
rast_input = dict(x_range=(-1, 10), y_range=(-1, 10), precompute=True, dynamic=False)
img = rasterize(Image(da), **rast_input)
output = img.data["z"].to_numpy()

np.testing.assert_array_equal(output, data.T)
assert not np.isnan(output).any()

# Setting expand=True with the {x,y}_ranges will expand the data with nan's
img = rasterize(Image(da), expand=True, **rast_input)
output = img.data["z"].to_numpy()
assert np.isnan(output).any()

class DatashaderSpreadTests(ComparisonTestCase):

Expand Down