Skip to content

Commit

Permalink
Merge pull request #4609 from robertcv/fix/binned_palette
Browse files Browse the repository at this point in the history
[FIX] colorpalettes: fix BinnedContinuousPalette color assignments
  • Loading branch information
janezd authored Apr 3, 2020
2 parents 7789901 + 76b3608 commit c999ab9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Orange/widgets/utils/colorpalettes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions Orange/widgets/utils/tests/test_colorpalettes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *

Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit c999ab9

Please sign in to comment.