Skip to content

Commit

Permalink
Fix array data not compatible with ComboBox (#652)
Browse files Browse the repository at this point in the history
* use is-operator to check separator

* use is-operator to check separator
  • Loading branch information
hanjinliu committed Jun 14, 2024
1 parent cec8109 commit e82a417
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/magicgui/backends/_qtpy/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)


Expand Down
14 changes: 14 additions & 0 deletions tests/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down

0 comments on commit e82a417

Please sign in to comment.