From 96838d0480a6b2548665df613d30b0ef89f8a57a Mon Sep 17 00:00:00 2001 From: Tobias Klockau Date: Tue, 19 Sep 2023 13:32:49 +0200 Subject: [PATCH] feat: warning duplicate frame id --- raillabel/format/raillabel/scene.py | 12 +++++++++++- .../format/raillabel/test_scene.py | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/raillabel/format/raillabel/scene.py b/raillabel/format/raillabel/scene.py index f7a48d5..4af5323 100644 --- a/raillabel/format/raillabel/scene.py +++ b/raillabel/format/raillabel/scene.py @@ -6,6 +6,7 @@ from ... import exceptions from ..._util._clean_dict import _clean_dict +from ..._util._warning import _warning from .frame import Frame from .frame_interval import FrameInterval from .metadata import Metadata @@ -200,7 +201,16 @@ def _frames_fromdict( frames = {} for frame_uid, frame_dict in frames_dict.items(): - frames[int(frame_uid)] = Frame.fromdict(frame_uid, frame_dict, objects, sensors) + frame_uid = int(frame_uid) + + if frame_uid in frames: + _warning( + f"Frame UID {frame_uid} is contained more than once in the scene. " + + "The duplicate frame will be omitted." + ) + continue + + frames[frame_uid] = Frame.fromdict(frame_uid, frame_dict, objects, sensors) return frames diff --git a/tests/test_raillabel/format/raillabel/test_scene.py b/tests/test_raillabel/format/raillabel/test_scene.py index e1d515e..d5cd687 100644 --- a/tests/test_raillabel/format/raillabel/test_scene.py +++ b/tests/test_raillabel/format/raillabel/test_scene.py @@ -10,6 +10,7 @@ sys.path.insert(1, str(Path(__file__).parent.parent.parent.parent.parent)) from raillabel import exceptions +from raillabel._util._warning import _WarningsLogger from raillabel.format import Frame, FrameInterval, Scene # == Fixtures ========================= @@ -273,6 +274,24 @@ def test_fromdict_frames( frame.uid: frame, } +def test_fromdict_duplicate_frame_id(metadata_full_dict): + with _WarningsLogger() as logger: + scene = Scene.fromdict( + { + "openlabel": { + "metadata": metadata_full_dict, + "frames": { + "0": {}, + "00": {}, + } + } + } + ) + + assert len(logger.warnings) == 1 + assert "0" in logger.warnings[0] + assert len(scene.frames) == 1 + def test_asdict_sensors( metadata_full, metadata_full_dict,