Skip to content

Commit c4d912a

Browse files
authored
Check for "/" in feature names (#660)
1 parent 4323bdc commit c4d912a

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

lerobot/common/datasets/lerobot_dataset.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,13 @@ def create(
304304
)
305305
else:
306306
# TODO(aliberts, rcadene): implement sanity check for features
307+
308+
# check if none of the features contains a "/" in their names,
309+
# as this would break the dict flattening in the stats computation, which uses '/' as separator
310+
for key in features:
311+
if "/" in key:
312+
raise ValueError(f"Feature names should not contain '/'. Found '/' in feature '{key}'.")
313+
307314
features = {**features, **DEFAULT_FEATURES}
308315

309316
obj.tasks, obj.stats, obj.episodes = {}, {}, []

tests/test_datasets.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,3 +414,20 @@ def test_create_branch():
414414

415415
# Clean
416416
api.delete_repo(repo_id, repo_type=repo_type)
417+
418+
419+
def test_dataset_feature_with_forward_slash_raises_error():
420+
# make sure dir does not exist
421+
from lerobot.common.datasets.lerobot_dataset import LEROBOT_HOME
422+
423+
dataset_dir = LEROBOT_HOME / "lerobot/test/with/slash"
424+
# make sure does not exist
425+
if dataset_dir.exists():
426+
dataset_dir.rmdir()
427+
428+
with pytest.raises(ValueError):
429+
LeRobotDataset.create(
430+
repo_id="lerobot/test/with/slash",
431+
fps=30,
432+
features={"a/b": {"dtype": "float32", "shape": 2, "names": None}},
433+
)

0 commit comments

Comments
 (0)