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] colorpalettes: fix BinnedContinuousPalette color assignments #4609

Merged
merged 1 commit into from
Apr 3, 2020
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
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