Skip to content

Commit 8bec9a2

Browse files
committed
[tools] Use odml tuple export
Closes #353, closes #250 Use the parser_utils odml_tuple_export function in xmlparser and dict_parser. It is required to properly serialize odml style tuples to XML, JSON and YAML files.
1 parent 70be784 commit 8bec9a2

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

odml/tools/dict_parser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from .. import format as odmlfmt
77
from ..info import FORMAT_VERSION
8-
from .parser_utils import InvalidVersionException, ParserException
8+
from .parser_utils import InvalidVersionException, ParserException, odml_tuple_export
99

1010

1111
class DictWriter:
@@ -107,8 +107,8 @@ def get_properties(props_list):
107107
elif (tag == []) or tag: # Even if 'values' is empty, allow '[]'
108108
# Custom odML tuples require special handling.
109109
if attr == "values" and prop.dtype and \
110-
prop.dtype.endswith("-tuple") and len(prop.values) > 0:
111-
prop_dict["value"] = "(%s)" % ";".join(prop.values[0])
110+
prop.dtype.endswith("-tuple") and prop.values:
111+
prop_dict["value"] = odml_tuple_export(prop.values)
112112
else:
113113
# Always use the arguments key attribute name when saving
114114
prop_dict[i] = tag

odml/tools/xmlparser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
from .. import format as ofmt
2424
from ..info import FORMAT_VERSION
25-
from .parser_utils import InvalidVersionException, ParserException
25+
from .parser_utils import InvalidVersionException, ParserException, odml_tuple_export
2626

2727
try:
2828
unicode = unicode
@@ -121,8 +121,8 @@ def save_element(curr_el):
121121
continue
122122
if isinstance(fmt, ofmt.Property.__class__) and k == "value":
123123
# Custom odML tuples require special handling for save loading from file.
124-
if curr_el.dtype and curr_el.dtype.endswith("-tuple") and len(val) > 0:
125-
ele = E(k, "(%s)" % ";".join(val[0]))
124+
if curr_el.dtype and curr_el.dtype.endswith("-tuple") and val:
125+
ele = E(k, odml_tuple_export(val))
126126
else:
127127
ele = E(k, to_csv(val))
128128
cur.append(ele)

0 commit comments

Comments
 (0)