Skip to content
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] EditDomain: Editing TimeVariable broke formatting #3101

Merged
merged 6 commits into from
Jun 29, 2018

Conversation

robertcv
Copy link
Collaborator

Issue

Fixes #2776

Description of changes

Add TimeVariableEditor and update variable_description and variable_from_description to correctly handle TimeVariables.

Includes
  • Code changes
  • Tests
  • Documentation

@CLAassistant
Copy link

CLAassistant commented Jun 28, 2018

CLA assistant check
All committers have signed the CLA.

@ajdapretnar
Copy link
Contributor

Looks ok to me! 👍

var.name,
(),
attributes)
if var.is_time:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason this is within an else statement?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it would be really better to use elif.

var.attributes.update(attrs)
if var.is_time:
var.have_date = kwargs['have_date']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you considered adding have_date and have_time to TimeVariable constructor as keyword arguments?

Copy link
Collaborator Author

@robertcv robertcv Jun 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was considering this but was afreide of breking something else, will add have_time and have_date as keyword arguments to TimeVariable constructor.


# if continuous variable edit is used have_time and have_date is not
# copied and the time string format is changed
idx = self.widget.domain_view.model().index(4)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# copied and the time string format is changed
idx = self.widget.domain_view.model().index(4)
self.widget.domain_view.setCurrentIndex(idx)
editor = self.widget.editor_stack.findChild(ContinuousVariableEditor)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why this is tested her. Can ContinuousVariableEditor be used for editing TimeVariable by users?

w.set_data(None)
self.assertEqual(w.name_edit.text(), "")
self.assertEqual(w.labels_model.get_dict(), {})
self.assertIs(w.get_data(), None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to add some tests that assure that the new variable has the same value for have_date and have_time as source.

if var.is_discrete:
editor_index = 0
elif var.is_continuous:
elif var.is_time:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment why time variables need to be handled before numeric variables?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TimeVariable is also continuous so we need to test if_time first. Will add comment.

@@ -412,6 +449,7 @@ def __init__(self):
self.editor_stack = QStackedWidget()

self.editor_stack.addWidget(DiscreteVariableEditor())
self.editor_stack.addWidget(TimeVariableEditor())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add this after ContinuousVariableEditor.

this way, the next diff should register as an addition of elif var.is_time as the elif var.is_continuous branch could remain unmodified

@astaric
Copy link
Member

astaric commented Jun 29, 2018

@kernc, are you ok with adding have_date and have_time kwargs to TimeVariable? They make construction of new variables where we already know what kind of datetime they contain much easier.

@astaric astaric changed the title [FIX][RFC] oweditdomain fix timevariable change [FIX] EditDomain: Editing TimeVariable broke formatting Jun 29, 2018
@ajdapretnar ajdapretnar merged commit 81b40d6 into biolab:master Jun 29, 2018
@kernc
Copy link
Contributor

kernc commented Jun 29, 2018

Was always in favor of setting parameters through the constructor. 👍

@robertcv robertcv deleted the fix_editdomain branch August 2, 2018 07:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants