Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_invalid_expression(self):
self.window._wait()
with dialogs.assertError(2):
self.layer.x = "vx*"
self.layer.y = "vy&"
with dialogs.assertError(3):
self.layer.x = "hoeba(vx)"
self.layer.x = "x(vx)"
self.layer.y = "doesnotexist"
with dialogs.assertError(2):
self.layer.vx = "hoeba(vx)"
self.layer.vy = "x(vx)"
with dialogs.assertError(1):
self.layer.weight = "hoeba(vx)"
self.layer.x = "x"
self.layer.y = "y"
self.layer.weight = "z"
#self.window._wait()
# since this will be triggered, overrule it
export(path, column_names=column_names, byteorder=byteorder, shuffle=shuffle, selection=selection)
else:
path = path_fits
path_ui = path_fits_ui
export(path, column_names=column_names, shuffle=shuffle, selection=selection)
compare_direct = vx.open(path)
dialogs.set_choose(1 if selection else 0).then("=<>".index(byteorder))
# select columns
dialogs.set_select_many(True, [name in column_names for name in dataset.get_column_names()])
counter_confirm = CallCounter(return_value=shuffle)
counter_info = CallCounter()
dialogs.dialog_confirm = counter_confirm
dialogs.dialog_info = counter_info
dialogs.get_path_save = lambda *args: path_ui
dialogs.ProgressExecution = dialogs.FakeProgressExecution
import sys
sys.stdout.flush()
self.app.export(type=type)
compare_ui = vx.open(path_ui)
column_names = column_names or ["x", "y", "z"]
self.assertEqual(compare_direct.get_column_names(), compare_ui.get_column_names())
for column_name in column_names:
values_ui = compare_ui.evaluate(column_name)
values = compare_direct.evaluate(column_name)
self.assertEqual(sorted(values), sorted(values_ui))
try:
unit = astropy.units.Unit(value)
logger.debug("setting unit to: %s (%s)" % (value, unit))
self.dataset.units[column_name] = unit
# TODO: move to dataset class
self.dataset.signal_column_changed.emit(self.dataset, column_name, "change")
except Exception as e:
dialogs.dialog_error(None, "Cannot parse unit", "Cannot parse unit:\n %s" % e)
else:
if column_name in self.dataset.units:
del self.dataset.units[column_name]
if property == "Expression":
try:
self.dataset.validate_expression(value)
except Exception as e:
dialogs.dialog_error(None, "Invalid expression", "Invalid expression: %s" % e)
# although it may not be a valid expression, still set it to the user can edit it
self.dataset.virtual_columns[column_name] = value
self.dataset.write_meta()
return True
if property == "Description":
self.dataset.descriptions[column_name] = value
if property == "UCD":
self.dataset.ucds[column_name] = value
# TODO: move to dataset class
self.dataset.signal_column_changed.emit(self.dataset, column_name, "change")
if property == "Units":
if value:
try:
unit = astropy.units.Unit(value)
logger.debug("setting unit to: %s (%s)" % (value, unit))
self.dataset.units[column_name] = unit
# TODO: move to dataset class
self.dataset.signal_column_changed.emit(self.dataset, column_name, "change")
except Exception as e:
dialogs.dialog_error(None, "Cannot parse unit", "Cannot parse unit:\n %s" % e)
else:
if column_name in self.dataset.units:
del self.dataset.units[column_name]
if property == "Expression":
try:
self.dataset.validate_expression(value)
except Exception as e:
dialogs.dialog_error(None, "Invalid expression", "Invalid expression: %s" % e)
# although it may not be a valid expression, still set it to the user can edit it
self.dataset.virtual_columns[column_name] = value
self.dataset.write_meta()
return True
_, ext = os.path.splitext(path)
if ext == ".yaml":
import yaml
with open(path) as f:
data = yaml.load(f)
elif ext == ".json":
import json
with open(path) as f:
json.load(f)
else:
dialogs.dialog_error(self, "Unknown extension", "Unknown extension %r" % ext)
try:
selection = vaex.dataset.selection_from_dict(self.dataset, data)
except Exception, e:
logger.exception("error reading in selection")
dialogs.dialog_error(self, "Error reading in selection", "Error reading in selection: %r" % e)
self.dataset.set_selection(selection)
self.queue_update()
self.action_selection_load = QtGui.QAction(QtGui.QIcon(iconfile('tag-import')), '&Load selection', self)
def error_dialog(self, widget, name, exception):
dialogs.dialog_error(widget, "Error", "%s: %r" % (name, exception))
def error_in_field(self, widget, name, exception):
def onActionSaveFrames(self, ignore=None):
#directory = QtGui.QFileDialog.getExistingDirectory(self, "Choose where to save frames", "", QtGui.QFileDialog.ShowDirsOnly | QtGui.QFileDialog.DontResolveSymlinks)
directory = qt.getdir(self, "Choose where to save frames", "")
self.frame_template = os.path.join(directory, "%s_{index:05}.png" % self.dataset.name)
self.frame_template = qt.gettext(self, "template for frame filenames", "template:", self.frame_template)
self.record_frames = True
self.onPlayOnce()
def onEditDescription(self):
text = dialogs.gettext(self, "Edit description", "Edit description", self.description.toPlainText())
if text is not None:
self.dataset.description = text
self.description.setText(text)
self.dataset.write_meta()
index = dialogs.choose(self, "What do you want to export?", "Choose what to export:", options)
if index is None:
return
export_selection = index == 1
logger.debug("export selection: %r", export_selection)
# select_many(None, "lala", ["aap", "noot"] + ["item-%d-%s" % (k, "-" * k) for k in range(30)])
ok, columns_mask = dialogs.select_many(self, "Select columns", dataset.get_column_names(virtual=True))
if not ok: # cancel
return
selected_column_names = [column_name for column_name, selected in zip(dataset.get_column_names(virtual=True), columns_mask) if selected]
logger.debug("export column names: %r", selected_column_names)
shuffle = dialogs.dialog_confirm(self, "Shuffle?", "Do you want the dataset to be shuffled (output the rows in random order)")
logger.debug("export shuffled: %r", shuffle)
if shuffle and dataset.length_original() != len(dataset):
dialogs.dialog_info(self, "Shuffle", "You selected shuffling while not exporting the full dataset, will select random rows from the full dataset")
partial_shuffle = True
else:
partial_shuffle = False
if export_selection and shuffle:
dialogs.dialog_info(self, "Shuffle", "Shuffling with selection not supported")
return
if type == "hdf5":
endian_options = ["Native", "Little endian", "Big endian"]
index = dialogs.choose(self, "Which endianness", "Which endianness / byte order:", endian_options)
if index is None:
return
def onActionSaveFrames(self, ignore=None):
#directory = QtGui.QFileDialog.getExistingDirectory(self, "Choose where to save frames", "", QtGui.QFileDialog.ShowDirsOnly | QtGui.QFileDialog.DontResolveSymlinks)
directory = qt.getdir(self, "Choose where to save frames", "")
self.frame_template = os.path.join(directory, "%s_{index:05}.png" % self.dataset.name)
self.frame_template = qt.gettext(self, "template for frame filenames", "template:", self.frame_template)
self.record_frames = True
self.onPlayOnce()