From bd27cf51ba5c4a766b24c3852d26346bc4dd481d Mon Sep 17 00:00:00 2001 From: jeromedockes Date: Mon, 28 Oct 2019 11:51:51 +0100 Subject: [PATCH] fix error when colorscale given boolean array (#2193) * fix error when colorscale given boolean array * add comment --- nilearn/plotting/js_plotting_utils.py | 2 ++ nilearn/plotting/tests/test_js_plotting_utils.py | 1 + 2 files changed, 3 insertions(+) diff --git a/nilearn/plotting/js_plotting_utils.py b/nilearn/plotting/js_plotting_utils.py index 5e41e2ae54..90e4efa222 100644 --- a/nilearn/plotting/js_plotting_utils.py +++ b/nilearn/plotting/js_plotting_utils.py @@ -87,6 +87,8 @@ def colorscale(cmap, values, threshold=None, symmetric_cmap=True, vmin = 0 if vmax is None: vmax = abs_values.max() + # cast to float to avoid TypeError if vmax is a numpy boolean + vmax = float(vmax) if symmetric_cmap: vmin = - vmax if vmin is None: diff --git a/nilearn/plotting/tests/test_js_plotting_utils.py b/nilearn/plotting/tests/test_js_plotting_utils.py index 06bc608b54..ffd6555ee4 100644 --- a/nilearn/plotting/tests/test_js_plotting_utils.py +++ b/nilearn/plotting/tests/test_js_plotting_utils.py @@ -62,6 +62,7 @@ def test_colorscale_no_threshold(): assert colors['cmap'].N == 256 assert (colors['norm'].vmax, colors['norm'].vmin) == (13, -13) assert colors['abs_threshold'] is None + colors = js_plotting_utils.colorscale(cmap, values > 0, .5) def test_colorscale_threshold_0():