Skip to content

Commit b5a2a94

Browse files
authored
Backward compat list feature (#7666)
backward compat list feature
1 parent cc40530 commit b5a2a94

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/datasets/features/features.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1759,10 +1759,20 @@ def __init__(*args, **kwargs):
17591759
raise TypeError("descriptor '__init__' of 'Features' object needs an argument")
17601760
self, *args = args
17611761
super(Features, self).__init__(*args, **kwargs)
1762+
# keep track of columns which require decoding
17621763
self._column_requires_decoding: dict[str, bool] = {
17631764
col: require_decoding(feature) for col, feature in self.items()
17641765
}
17651766

1767+
# backward compatibility with datasets<4 : [feature] -> List(feature)
1768+
def _check_old_list(feature):
1769+
if isinstance(feature, list):
1770+
return List(_visit(feature[0], _check_old_list))
1771+
return feature
1772+
1773+
for column_name, feature in self.items():
1774+
self[column_name] = _visit(feature, _check_old_list)
1775+
17661776
__setitem__ = keep_features_dicts_synced(dict.__setitem__)
17671777
__delitem__ = keep_features_dicts_synced(dict.__delitem__)
17681778
update = keep_features_dicts_synced(dict.update)

0 commit comments

Comments
 (0)