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

Fix default vdims in raster.RGB (round two) #5775

Merged
merged 1 commit into from
Jun 22, 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
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]
maximlt marked this conversation as resolved.
Show resolved Hide resolved

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