forked from M-Labs/artiq
1
0
Fork 0

dashboard/datasets: fix CreateEditDialog datatype cast (#2176)

This commit is contained in:
Simon Renblad 2023-09-01 13:59:17 +08:00 committed by GitHub
parent 9556ca53de
commit 01d777c977
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 6 deletions

View File

@ -78,10 +78,11 @@ class CreateEditDialog(QtWidgets.QDialog):
if metadata is not None: if metadata is not None:
scale = scale_from_metadata(metadata) scale = scale_from_metadata(metadata)
value = pyon.decode(value) decoded_value = pyon.decode(value)
t = type(value) if scale == 1:
if np.issubdtype(t, np.number) or t is np.ndarray: self.value_widget.setText(value)
self.value_widget.setText(pyon.encode(value / scale)) else:
self.value_widget.setText(pyon.encode(decoded_value / scale))
self.unit_widget.setText(metadata.get('unit', '')) self.unit_widget.setText(metadata.get('unit', ''))
self.scale_widget.setText(str(metadata.get('scale', ''))) self.scale_widget.setText(str(metadata.get('scale', '')))
self.precision_widget.setText(str(metadata.get('precision', ''))) self.precision_widget.setText(str(metadata.get('precision', '')))
@ -104,8 +105,9 @@ class CreateEditDialog(QtWidgets.QDialog):
metadata['precision'] = int(precision) metadata['precision'] = int(precision)
scale = scale_from_metadata(metadata) scale = scale_from_metadata(metadata)
value = pyon.decode(value) value = pyon.decode(value)
t = type(value) t = value.dtype if value is np.ndarray else type(value)
if np.issubdtype(t, np.number) or t is np.ndarray: is_floating = scale != 1 or np.issubdtype(t, np.floating)
if is_floating:
value = value * scale value = value * scale
if self.key and self.key != key: if self.key and self.key != key:
asyncio.ensure_future(exc_to_warning(rename(self.key, key, value, metadata, persist, self.dataset_ctl))) asyncio.ensure_future(exc_to_warning(rename(self.key, key, value, metadata, persist, self.dataset_ctl)))