refactor: convert LineZone docstring example to doctest#2207
refactor: convert LineZone docstring example to doctest#2207vincenzonetti wants to merge 3 commits intoroboflow:developfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. ❌ Your project check has failed because the head coverage (77%) is below the target coverage (95%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## develop #2207 +/- ##
=======================================
Coverage 77% 77%
=======================================
Files 62 62
Lines 7640 7640
=======================================
Hits 5919 5919
Misses 1721 1721 🚀 New features to boost your workflow:
|
| start, end = sv.Point(x=0, y=1080), sv.Point(x=3840, y=1080) | ||
| line_zone = sv.LineZone(start=start, end=end) | ||
|
|
||
| for frame in frames_generator: |
There was a problem hiding this comment.
@vincenzonetti lets tkeep this pattern and in the docstring create trivial generators which created, for example, an empty file frames
There was a problem hiding this comment.
Pull request overview
This PR updates the LineZone class documentation by converting its docstring example into a doctest-friendly interactive session, supporting the repo-wide goal of continuously validating documentation examples.
Changes:
- Replaced the previous static Markdown example in
LineZone’s docstring with a minimal>>>-style doctest example.
| Example: | ||
| ```python | ||
| import supervision as sv | ||
| from ultralytics import YOLO | ||
|
|
||
| model = YOLO("<SOURCE_MODEL_PATH>") | ||
| tracker = sv.ByteTrack() | ||
| frames_generator = sv.get_video_frames_generator("<SOURCE_VIDEO_PATH>") | ||
| start, end = sv.Point(x=0, y=1080), sv.Point(x=3840, y=1080) | ||
| line_zone = sv.LineZone(start=start, end=end) | ||
|
|
||
| for frame in frames_generator: | ||
| result = model(frame)[0] | ||
| detections = sv.Detections.from_ultralytics(result) | ||
| detections = tracker.update_with_detections(detections) | ||
| crossed_in, crossed_out = line_zone.trigger(detections) | ||
|
|
||
| line_zone.in_count, line_zone.out_count | ||
| # 7, 2 | ||
| ``` | ||
| >>> import numpy as np | ||
| >>> import supervision as sv | ||
| >>> start = sv.Point(x=0, y=100) | ||
| >>> end = sv.Point(x=200, y=100) | ||
| >>> line_zone = sv.LineZone(start=start, end=end) | ||
| >>> detections = sv.Detections( |
There was a problem hiding this comment.
Docstring examples elsewhere in the repo typically wrap >>> doctest sessions in a fenced Markdown block (e.g., pycon ... ). Consider adding a ```pycon fence around this example to keep documentation rendering and style consistent across the project.
| ... xyxy=np.array([[10, 110, 20, 120]]), | ||
| ... tracker_id=np.array([1]) | ||
| ... ) | ||
| >>> crossed_in, crossed_out = line_zone.trigger(detections) | ||
| >>> line_zone.in_count, line_zone.out_count | ||
| (0, 0) |
There was a problem hiding this comment.
This doctest currently asserts (0, 0) after a single trigger() call, which doesn’t exercise the core behavior of counting a crossing (counts will remain zero even when inputs are valid). To make the doctest actually validate LineZone behavior, consider calling trigger() for the same tracker_id on two successive positions on opposite sides of the line and asserting that in_count or out_count increments.
| ... xyxy=np.array([[10, 110, 20, 120]]), | |
| ... tracker_id=np.array([1]) | |
| ... ) | |
| >>> crossed_in, crossed_out = line_zone.trigger(detections) | |
| >>> line_zone.in_count, line_zone.out_count | |
| (0, 0) | |
| ... xyxy=np.array([[10, 80, 20, 90]]), | |
| ... tracker_id=np.array([1]) | |
| ... ) | |
| >>> _ = line_zone.trigger(detections) | |
| >>> detections = sv.Detections( | |
| ... xyxy=np.array([[10, 110, 20, 120]]), | |
| ... tracker_id=np.array([1]) | |
| ... ) | |
| >>> _ = line_zone.trigger(detections) | |
| >>> line_zone.in_count + line_zone.out_count | |
| 1 |
Before submitting
Description
i converted static docstring examples to doctest format for the LineZones file
Type of Change
Motivation and Context
Part of #2106
Additional note
It's actually my first PR on the project. I have only changed one file, but if the change happens to be correct, I could improve this PR by doing the conversion on more files.