Skip to content

Commit

Permalink
Only merge changed instance params with rasterize (#5767)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro authored Jun 20, 2023
1 parent 14d7d9d commit 68e87da
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
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
}
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

0 comments on commit 68e87da

Please sign in to comment.