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] Fix loading of datasets with paths in variable attributes #1549

Merged
merged 2 commits into from
Sep 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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