Skip to content

Commit

Permalink
Fix vdims in raster - Round two
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro committed Jun 21, 2023
1 parent be58b7e commit 2cd76d9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
5 changes: 3 additions & 2 deletions holoviews/element/raster.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from copy import deepcopy
from operator import itemgetter

import numpy as np
Expand Down Expand Up @@ -610,8 +611,8 @@ def __init__(self, data, kdims=None, vdims=None, **params):
arrays = [(im.data - r[0]) / (r[1] - r[0]) for r,im in zip(ranges, images)]
data = np.dstack(arrays)
if vdims is None:
# Same as the class variables, put here to secure the class variable is not used
vdims = [Dimension(c, range=(0,1)) for c in "RGB"]
# Need to make a deepcopy of the value so the RGB.default is not shared across instances
vdims = deepcopy(self.vdims)
else:
vdims = list(vdims) if isinstance(vdims, list) else [vdims]

Expand Down
15 changes: 14 additions & 1 deletion holoviews/tests/element/test_raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

import numpy as np
from holoviews.element import Raster, Image, Curve, QuadMesh, RGB
from holoviews.element import Raster, Image, Curve, QuadMesh, RGB, HSV
from holoviews.element.comparison import ComparisonTestCase

class TestRaster(ComparisonTestCase):
Expand Down Expand Up @@ -53,6 +53,19 @@ def test_not_using_class_variables_vdims(self):
cls_vdims = RGB.vdims
for i, c in zip(init_vdims, cls_vdims):
assert i is not c
assert i == c

class TestHSV(ComparisonTestCase):

def setUp(self):
self.hsv_array = np.random.randint(0, 255, (3, 3, 4))

def test_not_using_class_variables_vdims(self):
init_vdims = HSV(self.hsv_array).vdims
cls_vdims = HSV.vdims
for i, c in zip(init_vdims, cls_vdims):
assert i is not c
assert i == c

class TestQuadMesh(ComparisonTestCase):

Expand Down

0 comments on commit 2cd76d9

Please sign in to comment.