Skip to content

Commit

Permalink
feat: warning duplicate frame id
Browse files Browse the repository at this point in the history
  • Loading branch information
tklockau committed Sep 19, 2023
1 parent 729586c commit 96838d0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
12 changes: 11 additions & 1 deletion raillabel/format/raillabel/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
19 changes: 19 additions & 0 deletions tests/test_raillabel/format/raillabel/test_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 =========================
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 96838d0

Please sign in to comment.