From 2982329e285a4b5f99e8b3567822aa0c9a89f3b3 Mon Sep 17 00:00:00 2001 From: CarolinePascal Date: Thu, 7 May 2026 18:38:32 +0200 Subject: [PATCH] test(invalid key): adding test for invalid filtering key --- tests/datasets/test_datasets.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/datasets/test_datasets.py b/tests/datasets/test_datasets.py index 38ef79720..9d6553393 100644 --- a/tests/datasets/test_datasets.py +++ b/tests/datasets/test_datasets.py @@ -1739,9 +1739,21 @@ def test_episode_filter_no_match_raises(tmp_path, lerobot_dataset_factory): """An empty match in LeRobotDataset's episode_filter raises a ValueError rather than silently returning an empty dataset.""" dataset = lerobot_dataset_factory(root=tmp_path / "test", total_episodes=4, total_frames=100) - with pytest.raises(ValueError, match=r"episode_filter did not match any episode"): + with pytest.raises(ValueError, match=r"The episode filter did not match any episode"): LeRobotDataset( dataset.repo_id, root=dataset.root, episode_filter=lambda ep: ep["length"] < 0, ) + + +def test_episode_filter_unknown_key_raises(tmp_path, lerobot_dataset_factory): + """A predicate referencing a column absent from meta.episodes surfaces a clear KeyError.""" + dataset = lerobot_dataset_factory(root=tmp_path / "test", total_episodes=4, total_frames=100) + + with pytest.raises(KeyError, match="not_a_real_field"): + LeRobotDataset( + dataset.repo_id, + root=dataset.root, + episode_filter=lambda ep: ep["not_a_real_field"] > 0, + )