Skip to content

Commit ae43f03

Browse files
committed
Allow dicts to be serialized as str in kwargs
1 parent d511dea commit ae43f03

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

piff/readers.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,12 @@ def read_struct(self, name):
6363
cols = self._fits[extname].get_colnames()
6464
data = self._fits[extname].read()
6565
assert len(data) == 1
66-
return dict([ (col, data[col][0]) for col in cols ])
66+
struct = dict([ (col, data[col][0]) for col in cols ])
67+
# If any dicts were converted to str, convert back.
68+
for k,v in struct.items():
69+
if isinstance(v, str) and v[0] == '{':
70+
struct[k] = eval(v)
71+
return struct
6772

6873
def read_table(self, name, metadata=None):
6974
"""Load a table as a numpy array.

piff/writers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ def write_struct(self, name, struct):
7272
# Don't add values that are None to the table.
7373
if value is None:
7474
continue
75+
if isinstance(value, dict):
76+
value = repr(value)
7577
dt = make_dtype(key, value)
7678
value = adjust_value(value, dt)
7779
cols.append([value])

0 commit comments

Comments
 (0)