Skip to content

Commit

Permalink
Merge pull request #1549 from astaric/fix-attribute-save
Browse files Browse the repository at this point in the history
[FIX] Fix loading of datasets with paths in variable attributes
  • Loading branch information
rokgomiscek authored Sep 9, 2016
2 parents 44efe98 + f04649a commit d793eaf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Orange/data/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,13 @@ def __init__(self, flags):
if self._RE_ALL.match(flag):
if '=' in flag:
k, v = flag.split('=', 1)
self.attributes[k] = (v if Flags._RE_ATTR_UNQUOTED_STR(v) else
literal_eval(v) if v else
'')
if not Flags._RE_ATTR_UNQUOTED_STR(v):
try:
v = literal_eval(v)
except SyntaxError:
# If parsing failed, treat value as string
pass
self.attributes[k] = v
else:
setattr(self, flag, True)
setattr(self, self.ALL.get(flag, ''), True)
Expand Down Expand Up @@ -688,7 +692,7 @@ def read(self):
except Exception as e:
error = e
continue
raise ValueError('Cannot parse dataset {}: {}'.format(self.filename, error))
raise ValueError('Cannot parse dataset {}: {}'.format(self.filename, error)) from error

@classmethod
def write_file(cls, filename, data):
Expand Down
11 changes: 11 additions & 0 deletions Orange/tests/test_tab_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,17 @@ def test_read_and_save_attributes(self):
self.assertEqual(c1.name, "Class 1")
self.assertEqual(c1.attributes, {'x': 'a longer string'})

path = "/path/to/somewhere"
c1.attributes["path"] = path
outf = io.StringIO()
outf.close = lambda: None
TabReader.write_file(outf, table)
outf.seek(0)

table = read_tab_file(outf)
f1, f2, c1, c2 = table.domain.variables
self.assertEqual(c1.attributes["path"], path)

def test_read_data_oneline_header(self):
samplefile = """\
data1\tdata2\tdata3
Expand Down

0 comments on commit d793eaf

Please sign in to comment.