Preserve column ordering, setup->set_columns
@@ -22,7 +22,7 @@ class TypedTable(object):
A set of rows, which are dicts that share the same key set. The type
must be the same for a given key across rows. The type for each
- key must be set by calling setup() before adding any rows.
+ key must be set by calling set_columns() before adding any rows.
"""
def __init__(self, output):
@@ -31,35 +31,37 @@ class TypedTable(object):
self._types = {}
self._count = 0
- def setup(self, types):
+ def set_columns(self, types):
"""Set the column types
args:
types: iterable of (column_name, type) pairs.
"""
if self._types:
- raise wandb.Error('TypedTable.setup called more than once.')
+ raise wandb.Error('TypedTable.set_columns called more than once.')
try:
for key, type_ in types:
if type_ not in TYPE_TO_TYPESTRING:
- raise wandb.Error('TypedTable.setup received invalid type (%s) for key "%s".\n Valid types: %s' % (
+ raise wandb.Error('TypedTable.set_columns received invalid type (%s) for key "%s".\n Valid types: %s' % (
type_, key, '[%s]' % ', '.join(VALID_TYPE_NAMES)))
except TypeError:
raise wandb.Error(
- 'TypedTable.setup requires iterable of (column_name, type) pairs.')
+ 'TypedTable.set_columns requires iterable of (column_name, type) pairs.')
self._types = dict(types)
- self._output.add(
- {k: TYPE_TO_TYPESTRING[type_] for k, type_ in types})
+ self._output.add({
+ 'typemap': {k: TYPE_TO_TYPESTRING[type_] for k, type_ in types},
+ 'columns': [t[0] for t in types]})
def add(self, row):
"""Add a row to the table.
Args:
- row: A dict whose keys match the keys added in setup, and whose
- values can be cast to the types added in setup.
+ row: A dict whose keys match the keys added in set_columns, and whose
+ values can be cast to the types added in set_columns.
"""
if not self._types:
- raise wandb.Error('TypedTable.setup must be called before add.')
+ raise wandb.Error(
+ 'TypedTable.set_columns must be called before add.')
mapped_row = {}
for key, val in row.items():
try:
@@ -69,7 +71,7 @@ class TypedTable(object):
mapped_row[key] = typed_val
except KeyError:
raise wandb.Error(
- 'TypedTable.add received key ("%s") which wasn\'t provided to setup')
+ 'TypedTable.add received key ("%s") which wasn\'t provided to set_columns')
except:
raise wandb.Error('TypedTable.add couldn\'t convert and encode ("%s") provided for key ("%s") to type (%s)' % (
val, key, self._types[key]))
