-
-
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] Removed header types and flags from .csv and .tab #3427
Changes from 3 commits
7265793
fc34931
aea622d
e547593
a8f6517
863af59
7d0d3f4
1bd47c7
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 |
---|---|---|
|
@@ -431,8 +431,8 @@ def get_reader(cls, filename): | |
raise IOError('No readers for file "{}"'.format(filename)) | ||
|
||
@classmethod | ||
def write(cls, filename, data): | ||
return cls.write_file(filename, data) | ||
def write(cls, filename, data, with_annotations=True): | ||
return cls.write_file(filename, data, with_annotations) | ||
|
||
@classmethod | ||
def write_table_metadata(cls, filename, data): | ||
|
@@ -798,11 +798,12 @@ def header_flags(data): | |
zip(repeat('meta'), data.domain.metas))))) | ||
|
||
@classmethod | ||
def write_headers(cls, write, data): | ||
def write_headers(cls, write, data, with_annotations): | ||
"""`write` is a callback that accepts an iterable""" | ||
write(cls.header_names(data)) | ||
write(cls.header_types(data)) | ||
write(cls.header_flags(data)) | ||
if with_annotations: | ||
write(cls.header_types(data)) | ||
write(cls.header_flags(data)) | ||
|
||
@classmethod | ||
def formatter(cls, var): | ||
|
@@ -915,12 +916,13 @@ def read(self): | |
raise ValueError('Cannot parse dataset {}: {}'.format(self.filename, error)) from error | ||
|
||
@classmethod | ||
def write_file(cls, filename, data): | ||
def write_file(cls, filename, data, with_annotations=True): | ||
with cls.open(filename, mode='wt', newline='', encoding='utf-8') as file: | ||
writer = csv.writer(file, delimiter=cls.DELIMITERS[0]) | ||
cls.write_headers(writer.writerow, data) | ||
cls.write_headers(writer.writerow, data, with_annotations) | ||
cls.write_data(writer.writerow, data) | ||
cls.write_table_metadata(filename, data) | ||
if with_annotations: | ||
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 would remove this |
||
cls.write_table_metadata(filename, data) | ||
|
||
|
||
class TabReader(CSVReader): | ||
|
@@ -947,7 +949,7 @@ def read(self): | |
return table | ||
|
||
@classmethod | ||
def write_file(cls, filename, data): | ||
def write_file(cls, filename, data, with_annotations=True): | ||
with cls.open(filename, 'wb') as f: | ||
pickle.dump(data, f, pickle.HIGHEST_PROTOCOL) | ||
|
||
|
@@ -1024,7 +1026,7 @@ def read(self): | |
return table | ||
|
||
@classmethod | ||
def write_file(cls, filename, data): | ||
def write_file(cls, filename, data, with_annotations=True): | ||
vars = list(chain((ContinuousVariable('_w'),) if data.has_weights() else (), | ||
data.domain.attributes, | ||
data.domain.class_vars, | ||
|
@@ -1058,7 +1060,7 @@ def write_graph(cls, filename, graph): | |
tree.export_graphviz(graph, out_file=cls.open(filename, 'wt')) | ||
|
||
@classmethod | ||
def write(cls, filename, tree): | ||
def write(cls, filename, tree, with_annotations): | ||
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. Maybe |
||
if type(tree) == dict: | ||
tree = tree['tree'] | ||
cls.write_graph(filename, tree) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,7 @@ class Error(widget.OWWidget.Error): | |
filetype = Setting(FILE_TYPES[0][0]) | ||
compression = Setting(COMPRESSIONS[0][0]) | ||
compress = Setting(False) | ||
with_annotations = Setting(True) | ||
|
||
def __init__(self): | ||
super().__init__() | ||
|
@@ -89,6 +90,10 @@ def __init__(self): | |
|
||
box.layout().addLayout(form) | ||
|
||
self.annotations_cb = gui.checkBox( | ||
self.controlArea, self, "with_annotations", label="Save with Orange annotations", | ||
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. Maybe rename the setting to |
||
) | ||
|
||
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. You can fix the layout (checkbox not in the box, but outside and with a smaller indent) by changing this to:
The layout of this widget is awful anyway, but this is another issue. |
||
self.save = gui.auto_commit( | ||
self.controlArea, self, "auto_save", "Save", box=False, | ||
commit=self.save_file, callback=self.adjust_label, | ||
|
@@ -175,14 +180,18 @@ def save_file(self): | |
os.path.join( | ||
self.last_dir, | ||
self.basename + self.type_ext + self.compress_ext), | ||
self.data) | ||
self.data, self.with_annotations, | ||
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. This breaks compatibility with existing additional writers (if there are any!) that don't accept this argument. Writers that do not support it, should be called without it (see the general comment). |
||
) | ||
except Exception as err_value: | ||
self.error(str(err_value)) | ||
else: | ||
self.error() | ||
|
||
def update_extension(self): | ||
self.type_ext = [ext for name, ext, _ in FILE_TYPES if name == self.filetype][0] | ||
self.annotations_cb.setEnabled(True) | ||
if self.type_ext in ['.pkl', '.xlsx']: | ||
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. Whether this checkbox is shown should be decided by the file writer and not hard coded in the widget. See the general comment. |
||
self.annotations_cb.setEnabled(False) | ||
self.compress_ext = dict(COMPRESSIONS)[self.compression] if self.compress else '' | ||
|
||
def _update_text(self): | ||
|
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.
Maybe
with_annotations=True
?