From e82a41716637994c6f27934f71235b1d61323f72 Mon Sep 17 00:00:00 2001 From: Hanjin Liu <40591297+hanjinliu@users.noreply.github.com> Date: Sat, 15 Jun 2024 00:53:03 +0900 Subject: [PATCH] Fix array data not compatible with ComboBox (#652) * use is-operator to check separator * use is-operator to check separator --- src/magicgui/backends/_qtpy/widgets.py | 2 +- tests/test_widgets.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/magicgui/backends/_qtpy/widgets.py b/src/magicgui/backends/_qtpy/widgets.py index ed1fdb72..4d1ff753 100644 --- a/src/magicgui/backends/_qtpy/widgets.py +++ b/src/magicgui/backends/_qtpy/widgets.py @@ -988,7 +988,7 @@ def _mgui_get_choices(self) -> tuple[tuple[str, Any], ...]: return tuple( (self._qwidget.itemText(i), self._qwidget.itemData(i)) for i in range(self._qwidget.count()) - if self._qwidget.itemData(i) != Separator + if self._qwidget.itemData(i) is not Separator ) diff --git a/tests/test_widgets.py b/tests/test_widgets.py index 3e5dd35b..53ab9c39 100644 --- a/tests/test_widgets.py +++ b/tests/test_widgets.py @@ -287,6 +287,20 @@ def test_unhashable_choice_data(): combo.close() +def test_ambiguous_eq_choice_data(): + """Test that providing choice data with an ambiguous equal operation is ok.""" + import numpy as np + + combo = widgets.ComboBox() + assert not combo.choices + combo.choices = (("a", np.array([0, 0, 0])), ("b", np.array([1, 2, 3]))) + assert len(combo.choices) == 2 + assert np.all(combo.choices[0] == [0, 0, 0]) + assert np.all(combo.choices[1] == [1, 2, 3]) + + combo.close() + + def test_bound_values(): """Test that we can bind a "permanent" value override to a parameter."""