-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FIX] Edit Domain: Prevent duplicate variable names #2146
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2146 +/- ##
==========================================
+ Coverage 72.13% 72.14% +0.01%
==========================================
Files 318 318
Lines 54691 54717 +26
==========================================
+ Hits 39450 39476 +26
Misses 15241 15241 Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
The widget should indicate that the name is duplicated instead of silently ignoring the change.
-
The user can still assign the same new name to two attributes. I can rename all attributes to "foo".
Orange/widgets/data/oweditdomain.py
Outdated
@@ -196,11 +197,12 @@ def _setup_gui_labels(self): | |||
|
|||
self.main_form.addRow("Labels:", vlayout) | |||
|
|||
def set_data(self, var): | |||
def set_data(self, var, var_names=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using var_names=()
as default would simplify is_same
, wouldn't it?
Orange/widgets/data/oweditdomain.py
Outdated
@@ -308,16 +316,16 @@ def _setup_gui_values(self): | |||
self.values_model.dataChanged.connect(self.on_values_changed) | |||
self.main_form.addRow("Values:", self.values_edit) | |||
|
|||
def set_data(self, var): | |||
def set_data(self, var, var_names=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also here, you can probably replace None
with ()
.
Orange/widgets/data/oweditdomain.py
Outdated
@@ -505,7 +518,7 @@ def clear_editor(self): | |||
current.variable_changed.disconnect(self._on_variable_changed) | |||
except Exception: | |||
pass | |||
current.set_data(None) | |||
current.set_data(None, None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And then ()
(or nothing) instead of the second None
, too.
Orange/widgets/data/oweditdomain.py
Outdated
temp_var_names.remove(self.var.name) | ||
else: | ||
temp_var_names = [] | ||
return ((name in temp_var_names) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function checks whether it is necessary to change the domain. You shouldn't abuse it to check whether it's legal to change the domain. (See the general comment.)
Orange/widgets/data/oweditdomain.py
Outdated
@@ -402,6 +406,10 @@ def __init__(self): | |||
|
|||
box.layout().addWidget(self.editor_stack) | |||
|
|||
self.Warning.add_message( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think two variables with the same name should produce an error and require a fix before proceeding (instead of displaying a warning and working on)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, @janezd has different opinion (see above).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think @janezd didn't like that the change was ignored without a message. I don't see anything about whether the message should be a warning or an error.
We do not want to allow duplicate names (which is not just a cosmetic guideline, it can cause serious problems in the code, because we can index by names etc), so the widget should not output incorrect data. In that case an error is the only appropriate type of message.
Orange/widgets/data/oweditdomain.py
Outdated
self.domain_model[self.selected_index] = new_var | ||
|
||
|
||
var_names = [vn.name for vn in self.domain_model] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now checked only on variable changes. If I see the warning and reset a variable to the original, the warning does not disappear (the reset functions don't reach this code).
Maybe the check could be moved to commit:
- if everything is ok, remove the error and proceed
- if not, show the error and send None
Also, editing a variable name and pressing enter does not work... Maybe that's a separate issue, but if it is easy to fix it can perhaps be added here? |
@lanzagar: Yes, pressing enter is another issue. |
White spaces in the beginning and in the end of the name are removed. Empty names are not allowed. GH-2143
Issue
Edit Domain enables us to write duplicate names and that should be allowed. However user should be informed about that.
#2143
Description of changes
User is warned when writing a duplicate name. Also, empty spaces are removed in the beginning and in the end of a new name.
Includes