From 4addff6a314e112452fa8bfe93ae5f97de211f82 Mon Sep 17 00:00:00 2001 From: jernej-local Date: Tue, 21 Feb 2017 09:48:09 +0100 Subject: [PATCH] [FIX] Prevent PickleError (domaineditor & test_owfile) PickleError thrown if a column does not have a name. Column name cannot be changed to an empty string or a string with whitespaces. --- Orange/widgets/data/owfile.py | 3 +-- Orange/widgets/data/tests/test_owfile.py | 12 ++++++++++++ Orange/widgets/utils/domaineditor.py | 13 +++++++------ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Orange/widgets/data/owfile.py b/Orange/widgets/data/owfile.py index 5071496ca75..2f58b0704dc 100644 --- a/Orange/widgets/data/owfile.py +++ b/Orange/widgets/data/owfile.py @@ -5,8 +5,7 @@ import numpy as np from AnyQt.QtWidgets import \ QStyle, QComboBox, QMessageBox, QFileDialog, QGridLayout, QLabel, \ - QLineEdit -from AnyQt.QtWidgets import QSizePolicy as Policy + QLineEdit, QSizePolicy as Policy from AnyQt.QtCore import Qt, QTimer, QSize from Orange.canvas.gui.utils import OSX_NSURL_toLocalFile diff --git a/Orange/widgets/data/tests/test_owfile.py b/Orange/widgets/data/tests/test_owfile.py index 10dec85bd43..9205fe04f9c 100644 --- a/Orange/widgets/data/tests/test_owfile.py +++ b/Orange/widgets/data/tests/test_owfile.py @@ -127,3 +127,15 @@ def test_file_not_found(self): # Open a sample dataset self.open_dataset("iris") self.assertFalse(self.widget.Error.file_not_found.is_shown()) + + def test_check_column_noname(self): + """ + GH-2018 + """ + self.open_dataset("iris") + idx = self.widget.domain_editor.model().createIndex(1, 0) + temp = self.widget.domain_editor.model().data(idx, Qt.DisplayRole) + self.widget.domain_editor.model().setData(idx, " ", Qt.EditRole) + self.assertEqual(self.widget.domain_editor.model().data(idx, Qt.DisplayRole), temp) + self.widget.domain_editor.model().setData(idx, "", Qt.EditRole) + self.assertEqual(self.widget.domain_editor.model().data(idx, Qt.DisplayRole), temp) diff --git a/Orange/widgets/utils/domaineditor.py b/Orange/widgets/utils/domaineditor.py index 0af265f0283..0484269f95d 100644 --- a/Orange/widgets/utils/domaineditor.py +++ b/Orange/widgets/utils/domaineditor.py @@ -79,7 +79,7 @@ def setData(self, index, value, role): row, col = index.row(), index.column() row_data = self.variables[row] if role == Qt.EditRole: - if col == Column.name: + if col == Column.name and not (value.isspace() or value == ""): row_data[col] = value elif col == Column.tpe: vartype = self.name2type[value] @@ -125,7 +125,7 @@ def showPopup(self, *args): def hidePopup(me): if me.popup_shown: self.view.model().setData( - index, me.highlighted_text, Qt.EditRole) + index, me.highlighted_text, Qt.EditRole) self.popup_shown = False super().hidePopup() self.view.closeEditor(me, self.NoHint) @@ -211,9 +211,9 @@ def is_missing(x): for (name, tpe, place, _, _), (orig_var, orig_plc) in \ zip(variables, - chain([(at, Place.feature) for at in domain.attributes], - [(cl, Place.class_var) for cl in domain.class_vars], - [(mt, Place.meta) for mt in domain.metas])): + chain([(at, Place.feature) for at in domain.attributes], + [(cl, Place.class_var) for cl in domain.class_vars], + [(mt, Place.meta) for mt in domain.metas])): if place == Place.skip: continue if orig_plc == Place.meta: @@ -277,7 +277,8 @@ def may_be_numeric(var): return False def discrete_value_display(value_list): - result = ", ".join(str(v) for v in value_list[:VarTableModel.DISCRETE_VALUE_DISPLAY_LIMIT]) + result = ", ".join(str(v) + for v in value_list[:VarTableModel.DISCRETE_VALUE_DISPLAY_LIMIT]) if len(value_list) > VarTableModel.DISCRETE_VALUE_DISPLAY_LIMIT: result += ", ..." return result