Skip to content

Commit fc34931

Browse files
enable no annotations save for .csv and .tab
1 parent 7265793 commit fc34931

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

Orange/data/io.py

+12-14
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,8 @@ def get_reader(cls, filename):
431431
raise IOError('No readers for file "{}"'.format(filename))
432432

433433
@classmethod
434-
def write(cls, filename, data):
435-
return cls.write_file(filename, data)
434+
def write(cls, filename, data, with_annotations=True):
435+
return cls.write_file(filename, data, with_annotations)
436436

437437
@classmethod
438438
def write_table_metadata(cls, filename, data):
@@ -798,11 +798,12 @@ def header_flags(data):
798798
zip(repeat('meta'), data.domain.metas)))))
799799

800800
@classmethod
801-
def write_headers(cls, write, data):
801+
def write_headers(cls, write, data, with_annotations):
802802
"""`write` is a callback that accepts an iterable"""
803803
write(cls.header_names(data))
804-
write(cls.header_types(data))
805-
write(cls.header_flags(data))
804+
if with_annotations:
805+
write(cls.header_types(data))
806+
write(cls.header_flags(data))
806807

807808
@classmethod
808809
def formatter(cls, var):
@@ -915,16 +916,13 @@ def read(self):
915916
raise ValueError('Cannot parse dataset {}: {}'.format(self.filename, error)) from error
916917

917918
@classmethod
918-
def write_file(cls, filename, data):
919+
def write_file(cls, filename, data, with_annotations=True):
919920
with cls.open(filename, mode='wt', newline='', encoding='utf-8') as file:
920921
writer = csv.writer(file, delimiter=cls.DELIMITERS[0])
921-
cls.write_headers(writer.writerow, data)
922+
cls.write_headers(writer.writerow, data, with_annotations)
922923
cls.write_data(writer.writerow, data)
923-
cls.write_table_metadata(filename, data)
924-
925-
@classmethod
926-
def write_headers(cls, write, data):
927-
write(cls.header_names(data))
924+
if with_annotations:
925+
cls.write_table_metadata(filename, data)
928926

929927

930928
class TabReader(CSVReader):
@@ -951,7 +949,7 @@ def read(self):
951949
return table
952950

953951
@classmethod
954-
def write_file(cls, filename, data):
952+
def write_file(cls, filename, data, with_annotations=True):
955953
with cls.open(filename, 'wb') as f:
956954
pickle.dump(data, f, pickle.HIGHEST_PROTOCOL)
957955

@@ -1062,7 +1060,7 @@ def write_graph(cls, filename, graph):
10621060
tree.export_graphviz(graph, out_file=cls.open(filename, 'wt'))
10631061

10641062
@classmethod
1065-
def write(cls, filename, tree):
1063+
def write(cls, filename, tree, with_annotations):
10661064
if type(tree) == dict:
10671065
tree = tree['tree']
10681066
cls.write_graph(filename, tree)

Orange/widgets/data/owsave.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class Error(widget.OWWidget.Error):
4848
filetype = Setting(FILE_TYPES[0][0])
4949
compression = Setting(COMPRESSIONS[0][0])
5050
compress = Setting(False)
51+
with_annotations = Setting(True)
5152

5253
def __init__(self):
5354
super().__init__()
@@ -89,6 +90,10 @@ def __init__(self):
8990

9091
box.layout().addLayout(form)
9192

93+
self.annotations_cb = gui.checkBox(
94+
self.controlArea, self, "with_annotations", label="Save with Orange annotations",
95+
)
96+
9297
self.save = gui.auto_commit(
9398
self.controlArea, self, "auto_save", "Save", box=False,
9499
commit=self.save_file, callback=self.adjust_label,
@@ -175,14 +180,18 @@ def save_file(self):
175180
os.path.join(
176181
self.last_dir,
177182
self.basename + self.type_ext + self.compress_ext),
178-
self.data)
183+
self.data, self.with_annotations,
184+
)
179185
except Exception as err_value:
180186
self.error(str(err_value))
181187
else:
182188
self.error()
183189

184190
def update_extension(self):
185191
self.type_ext = [ext for name, ext, _ in FILE_TYPES if name == self.filetype][0]
192+
self.annotations_cb.setEnabled(True)
193+
if self.type_ext == '.pkl':
194+
self.annotations_cb.setEnabled(False)
186195
self.compress_ext = dict(COMPRESSIONS)[self.compression] if self.compress else ''
187196

188197
def _update_text(self):

0 commit comments

Comments
 (0)