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 all 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 is value2) or (value1 == value2)
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
13 changes: 12 additions & 1 deletion holoviews/operation/datashader.py
Original file line number Diff line number Diff line change
Expand Up @@ -1374,12 +1374,23 @@ class rasterize(AggregationOperation):
(type(None), shade) # To handle parameters of datashade
]

__instance_params = set()

@bothmethod
def instance(self_or_cls, **params):
inst = super().instance(**params)
inst.__instance_params = set(params)
return inst

def _process(self, element, key=None):
# Potentially needs traverse to find element types first?
all_allowed_kws = set()
all_supplied_kws = set()
instance_params = {
k: getattr(self, k) for k in self.__instance_params
}
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(instance_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