File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed
Orange/widgets/unsupervised Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -833,6 +833,17 @@ def set_color_bins(self):
833833 binning = decimal_binnings (col , min_bins = 4 )[- 1 ]
834834 self .thresholds = binning .thresholds [1 :- 1 ]
835835 self .bin_labels = (binning .labels [1 :- 1 ], binning .short_labels [1 :- 1 ])
836+ if not self .bin_labels [0 ] and binning .labels :
837+ # Nan's are already filtered out, but it doesn't hurt much
838+ # to use nanmax/nanmin
839+ if np .nanmin (col ) == np .nanmax (col ):
840+ # Handle a degenerate case with a single value
841+ # Use the second threshold (because value must be smaller),
842+ # but the first threshold as label (because that's the
843+ # actual value in the data.
844+ self .thresholds = binning .thresholds [1 :]
845+ self .bin_labels = (binning .labels [:1 ],
846+ binning .short_labels [:1 ])
836847 palette = BinnedContinuousPalette .from_palette (
837848 self .attr_color .palette , binning .thresholds )
838849 self .colors = palette
@@ -871,6 +882,8 @@ def create_legend(self):
871882
872883 def _bin_names (self ):
873884 labels , short_labels = self .bin_labels
885+ if len (labels ) <= 1 :
886+ return labels
874887 return \
875888 [f"< { labels [0 ]} " ] \
876889 + [f"{ x } - { y } " for x , y in zip (labels , short_labels [1 :])] \
Original file line number Diff line number Diff line change 88
99from Orange .data import Table , Domain
1010from Orange .widgets .tests .base import WidgetTest
11+ from Orange .widgets .tests .utils import simulate
1112from Orange .widgets .utils .annotated_data import ANNOTATED_DATA_FEATURE_NAME
1213from Orange .widgets .unsupervised .owsom import OWSOM , SomView , SOM
1314
@@ -220,6 +221,14 @@ def test_attr_color_change(self):
220221 self .assertIsNotNone (widget .thresholds )
221222 widget ._redraw .assert_called ()
222223
224+ def test_colored_circles_with_constant (self ):
225+ with self .iris .unlocked ():
226+ self .iris .X [:, 0 ] = 1
227+ self .send_signal (self .widget .Inputs .data , self .iris )
228+ combo = self .widget .controls .attr_color
229+ simulate .combobox_activate_index (
230+ combo , combo .model ().indexOf (self .iris .domain .attributes [0 ]))
231+
223232 @_patch_recompute_som
224233 def test_cell_sizes (self ):
225234 widget = self .widget
You can’t perform that action at this time.
0 commit comments