Skip to content

Commit

Permalink
Fix ValueError for empty arrays in FloatArrayItem
Browse files Browse the repository at this point in the history
Fix #80
  • Loading branch information
PierreRaybaut committed Nov 14, 2024
1 parent b5d5e69 commit 1b0579d
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog #

## Version 3.7.2 ##

🛠️ Bug fixes:

* [Issue #80](https://github.com/PlotPyStack/guidata/issues/80) - `ValueError` when trying to show/edit an empty array

## Version 3.7.1 ##

ℹ️ Changes:
Expand Down
2 changes: 1 addition & 1 deletion guidata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
and application development tools for Qt.
"""

__version__ = "3.7.1"
__version__ = "3.7.2"


# Dear (Debian, RPM, ...) package makers, please feel free to customize the
Expand Down
4 changes: 3 additions & 1 deletion guidata/dataset/dataitems.py
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,9 @@ def format_string(
larg = self.get_prop_value("display", instance, "large", False)
fmt = self.get_prop_value("display", instance, "format", "%s")
unit = self.get_prop_value("display", instance, "unit", "")
v = func(value)
v: np.ndarray = func(value)
if v.size == 0:
return "= []"
if larg:
text = "= ["
for flt in v[:-1]:
Expand Down
2 changes: 1 addition & 1 deletion guidata/dataset/qtitemwidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1314,7 +1314,7 @@ def update(self, arr: np.ndarray) -> None:
maxt = ", ".join(
[format % real_arr[:, r].max() for r in range(arr.shape[1])]
)
except (TypeError, IndexError):
except (TypeError, IndexError, ValueError):
mint, maxt = "-", "-"
self.min_label.setText(mint)
self.max_label.setText(maxt)
Expand Down
3 changes: 3 additions & 0 deletions guidata/tests/dataset/test_all_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ class Parameters(gds.DataSet):
floatarray = gds.FloatArrayItem(
"Float array", default=np.ones((50, 5), float), format=" %.2e "
).set_pos(col=1)
floatarray2 = gds.FloatArrayItem(
"Empty array", default=np.array([], float)
).set_pos(col=2)
g0 = gds.BeginTabGroup("group")
mchoice1 = gds.MultipleChoiceItem(
"MC type 1", ["first choice", "second choice", "third choice"]
Expand Down

0 comments on commit 1b0579d

Please sign in to comment.