-
-
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
Edit Domain: add custom format #6848
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
# pylint: disable=all | ||
import pickle | ||
import unittest | ||
from datetime import datetime, timezone | ||
from functools import partial | ||
from itertools import product, chain | ||
from unittest import TestCase | ||
|
@@ -340,6 +341,38 @@ def test_time_variable_preservation(self): | |
output = self.get_output(self.widget.Outputs.data) | ||
self.assertEqual(str(table[0, 4]), str(output[0, 4])) | ||
|
||
def test_custom_format(self): | ||
time_variable = StringVariable("Date") | ||
data = [ | ||
["2024-001"], | ||
["2024-032"], | ||
["2024-150"], | ||
["2024-365"] | ||
] | ||
table = Table.from_list(Domain([], metas=[time_variable]), data) | ||
self.send_signal(self.widget.Inputs.data, table) | ||
index = self.widget.variables_view.model().index | ||
self.widget.variables_view.setCurrentIndex(index(0)) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your original variable is a string. You must change its type to time variable, like this:
When you saw an "unchanged" date, it was because your variable remained a string, and changes that you made in the edit dialog were ignored. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know the variable didn't change (it stayed StringVariable). I said I tried everything, we even had a look at the code with Lan, but couldn't figure out how to write a proper call. |
||
editor = self.widget.findChild(VariableEditor) | ||
tc = editor.layout().currentWidget().findChild(QComboBox, | ||
name="type-combo") | ||
tc.setCurrentIndex(3) # time variable | ||
tc.activated.emit(3) | ||
|
||
# le = editor.layout().currentWidget().findChild(QLineEdit) | ||
# le.setText("%Y-%j") | ||
# le.editingFinished.emit() | ||
|
||
self.widget.commit() | ||
output = self.get_output(self.widget.Outputs.data) | ||
print(output) | ||
self.assertEqual(table.metas[0, 0], "2024-001") | ||
self.assertEqual(output.metas[0, 0], | ||
datetime.strptime("2024-001", | ||
"%Y-%j").replace( | ||
tzinfo=timezone.utc).timestamp()) | ||
|
||
def test_restore(self): | ||
iris = self.iris | ||
viris = ( | ||
|
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.
Don't forget to remove this! I suggest you remove it now, and when you're making commits, add with
add -p
and skip this chunk.