Exception to alert user of possible mistake when providing label and label candidate
@@ -228,10 +228,13 @@ class DialogData(object):
new_entry.append(None)
if len(entry) > 1:
# process labels if available
- if entry[1] is not None:
+ if entry[1] is None:
+ new_entry.append(None)
+ elif hasattr(entry[1], '__iter__') and type(entry[1]) is not str:
+ # make sure iterable over labels, not single string
new_entry.append(tuple(sys.intern(e) for e in entry[1]))
else:
- new_entry.append(None)
+ raise TypeError('Must provide iterable over labels, not a single string.')
if len(entry) > 2:
# process reward if available
if entry[2] is not None:
@@ -239,19 +242,21 @@ class DialogData(object):
else:
new_entry.append(None)
if len(entry) > 3:
- if entry[3] is not None:
# process label candidates if available
- if last_cands and entry[3] is last_cands:
+ if entry[3] is None:
+ new_entry.append(None)
+ elif last_cands and entry[3] is last_cands:
# if cands are shared, say "same" so we
# don't store them again
new_entry.append(
sys.intern('same as last time'))
- else:
+ elif hasattr(entry[3], '__iter__') and type(entry[3]) is not str:
+ # make sure iterable over candidates, not single string
last_cands = entry[3]
new_entry.append(tuple(
sys.intern(e) for e in entry[3]))
else:
- new_entry.append(None)
+ raise TypeError('Must provide iterable over label candidates, not a single string.')
if len(entry) > 4 and entry[4] is not None:
new_entry.append(sys.intern(entry[4]))
