diff --git a/Orange/widgets/utils/colorpalettes.py b/Orange/widgets/utils/colorpalettes.py index 0a0efc470fa..a71297045d4 100644 --- a/Orange/widgets/utils/colorpalettes.py +++ b/Orange/widgets/utils/colorpalettes.py @@ -394,7 +394,7 @@ def from_palette(cls, palette, bins): def _bin_indices(self, x): nans = np.isnan(x) - binx = np.digitize(x, self.bins[1:-1], right=True) + binx = np.digitize(x, self.bins[1:-1]) binx.clip(0, len(self.bins) - 1) binx[nans] = -1 return binx, nans diff --git a/Orange/widgets/utils/tests/test_colorpalettes.py b/Orange/widgets/utils/tests/test_colorpalettes.py index fe92a32d8ce..5a6321a44b0 100644 --- a/Orange/widgets/utils/tests/test_colorpalettes.py +++ b/Orange/widgets/utils/tests/test_colorpalettes.py @@ -9,6 +9,7 @@ from orangewidget.tests.base import GuiTest from Orange.util import color_to_hex from Orange.data import DiscreteVariable, ContinuousVariable, Variable +from Orange.preprocess.discretize import decimal_binnings # pylint: disable=wildcard-import,unused-wildcard-import from Orange.widgets.utils.colorpalettes import * @@ -464,6 +465,14 @@ def test_copy(self): copy.bins[0] += 1 self.assertNotEqual(self.bins[0], copy.bins[0]) + def test_decimal_binnings(self): + """test for consistency with binning from discretize""" + data = np.array([1, 2]) + bins = decimal_binnings(data)[0].thresholds + binned = BinnedContinuousPalette.from_palette(self.palette, bins) + colors = binned.values_to_colors(data) + assert not np.array_equal(colors[0], colors[1]) + class UtilsTest(GuiTest): def test_coloricon(self):