Skip to content

Commit

Permalink
Fix tests on builds (#4590)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Sep 3, 2020
1 parent 1f4c318 commit 8168fa1
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 25 deletions.
3 changes: 3 additions & 0 deletions holoviews/plotting/bokeh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
DivPlot, LabelsPlot, SlopePlot
)
from ..plot import PlotSelector
from ..util import fire
from .callbacks import Callback # noqa (API import)
from .element import OverlayPlot, ElementPlot
from .chart import (PointPlot, CurvePlot, SpreadPlot, ErrorPlot, HistogramPlot,
Expand Down Expand Up @@ -158,6 +159,8 @@ def colormap_generator(palette):
if max(p.keys()) < 256})

dflt_cmap = 'fire'
all_palettes['fire'] = {len(fire): fire}

options = Store.options(backend='bokeh')

# Charts
Expand Down
10 changes: 9 additions & 1 deletion holoviews/plotting/mpl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import os

from matplotlib import rc_params_from_file
from matplotlib.colors import ListedColormap
from matplotlib.colors import ListedColormap, LinearSegmentedColormap
from matplotlib.cm import register_cmap
from param import concrete_descendents

from ...core import Layout, Collator, GridMatrix, config
Expand All @@ -12,6 +13,7 @@
from ...core.util import LooseVersion, pd
from ...element import * # noqa (API import)
from ..plot import PlotSelector
from ..util import fire_colors
from .annotation import * # noqa (API import)
from .chart import * # noqa (API import)
from .chart3d import * # noqa (API import)
Expand Down Expand Up @@ -211,6 +213,12 @@ def grid_selector(grid):
QuadMeshPlot, HeatMapPlot, PolygonPlot]:
framedcls.show_frame = True

fire_cmap = LinearSegmentedColormap.from_list("fire", fire_colors, N=len(fire_colors))
fire_r_cmap = LinearSegmentedColormap.from_list("fire_r", list(reversed(fire_colors)),
N=len(fire_colors))
register_cmap("fire", cmap=fire_cmap)
register_cmap("fire_r", cmap=fire_r_cmap)

options = Store.options(backend='matplotlib')
dflt_cmap = 'fire'
# Default option definitions
Expand Down
18 changes: 5 additions & 13 deletions holoviews/plotting/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ def bokeh_palette_to_palette(cmap, ncolors=None, categorical=False):

# Handle categorical colormaps to avoid interpolation
categories = ['accent', 'category', 'dark', 'colorblind', 'pastel',
'set1', 'set2', 'set3', 'paired']
'set1', 'set2', 'set3', 'paired']
cmap_categorical = any(cat in cmap.lower() for cat in categories)
reverse = False
if cmap.endswith('_r'):
Expand All @@ -605,7 +605,10 @@ def bokeh_palette_to_palette(cmap, ncolors=None, categorical=False):
cmap = cmap.replace('tab', 'Category')

# Process as bokeh palette
palette = getattr(palettes, cmap, getattr(palettes, cmap.capitalize(), None))
if cmap in palettes.all_palettes:
palette = palettes.all_palettes[cmap]
else:
palette = getattr(palettes, cmap, getattr(palettes, cmap.capitalize(), None))
if palette is None:
raise ValueError("Supplied palette %s not found among bokeh palettes" % cmap)
elif isinstance(palette, dict) and (cmap in palette or cmap.capitalize() in palette):
Expand Down Expand Up @@ -1241,14 +1244,3 @@ def hex2rgb(hex):
# Bokeh palette
fire = [str('#{0:02x}{1:02x}{2:02x}'.format(int(r*255),int(g*255),int(b*255)))
for r,g,b in fire_colors]

# Matplotlib colormap
try:
from matplotlib.colors import LinearSegmentedColormap
from matplotlib.cm import register_cmap
fire_cmap = LinearSegmentedColormap.from_list("fire", fire_colors, N=len(fire_colors))
fire_r_cmap = LinearSegmentedColormap.from_list("fire_r", list(reversed(fire_colors)), N=len(fire_colors))
register_cmap("fire", cmap=fire_cmap)
register_cmap("fire_r", cmap=fire_r_cmap)
except ImportError:
pass
39 changes: 28 additions & 11 deletions holoviews/tests/core/testdecollation.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
from unittest import skipIf

import param

from holoviews.core import HoloMap, NdOverlay, Overlay, GridSpace, DynamicMap
from holoviews.element import Points
from holoviews.element.comparison import ComparisonTestCase
from holoviews.streams import Stream, PlotSize, RangeXY
from holoviews.operation.datashader import spread, datashade
import param

try:
from holoviews.operation.datashader import spread, datashade
except:
spread = datashade = None

datashade_skip = skipIf(datashade is None, "datashade is not available")


class XY(Stream):
Expand Down Expand Up @@ -44,15 +53,6 @@ def setUp(self):
lambda z: Points([z, z]), streams=[self.z_stream]
)

# dmap produced by chained datashade and shade
self.px_stream = PX()
self.dmap_spread_points = spread(
datashade(Points([0.0, 1.0])), streams=[self.px_stream]
)

# data shaded with kdims: a, b
self.dmap_datashade_kdim_points = datashade(self.dmap_ab)

# DynamicMap of a derived stream
self.stream_val1 = Val()
self.stream_val2 = Val()
Expand All @@ -64,6 +64,19 @@ def setUp(self):
]
)

if datashade is None:
return

# dmap produced by chained datashade and shade
self.px_stream = PX()
self.dmap_spread_points = spread(
datashade(Points([0.0, 1.0])), streams=[self.px_stream]
)

# data shaded with kdims: a, b
self.dmap_datashade_kdim_points = datashade(self.dmap_ab)


def test_decollate_layout_kdims(self):
layout = self.dmap_ab + self.dmap_b
decollated = layout.decollate()
Expand Down Expand Up @@ -114,6 +127,7 @@ def test_decollate_layout_kdims_and_streams(self):
Points([1.0, 2.0]) + Points([3.0, 4.0])
)

@datashade_skip
def test_decollate_spread(self):
decollated = self.dmap_spread_points.decollate()
self.assertIsInstance(decollated, DynamicMap)
Expand All @@ -140,6 +154,7 @@ def test_decollate_spread(self):

self.assertEqual(expected, result)

@datashade_skip
def test_decollate_datashade_kdims(self):
decollated = self.dmap_datashade_kdim_points.decollate()
self.assertIsInstance(decollated, DynamicMap)
Expand Down Expand Up @@ -169,6 +184,8 @@ def test_decollate_datashade_kdims(self):

self.assertEqual(expected, result)


@datashade_skip
def test_decollate_datashade_kdims_layout(self):
layout = self.dmap_datashade_kdim_points + self.dmap_b

Expand Down

0 comments on commit 8168fa1

Please sign in to comment.