Skip to content

refactor: convert LineZone docstring example to doctest#2207

Open
vincenzonetti wants to merge 3 commits intoroboflow:developfrom
vincenzonetti:refactor/doctest-conversion
Open

refactor: convert LineZone docstring example to doctest#2207
vincenzonetti wants to merge 3 commits intoroboflow:developfrom
vincenzonetti:refactor/doctest-conversion

Conversation

@vincenzonetti
Copy link
Copy Markdown

@vincenzonetti vincenzonetti commented Apr 7, 2026

Before submitting
  • Self-reviewed the code
  • Updated documentation, follow Google-style
  • Added docs entry for autogeneration (if new functions/classes)

Description

i converted static docstring examples to doctest format for the LineZones file

Type of Change

  • 📝 Documentation update

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.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 7, 2026

CLA assistant check
All committers have signed the CLA.

@Borda Borda requested a review from Copilot April 8, 2026 12:35
@Borda Borda changed the title refactor: convert LineZone docstring example to doctest (#2106) refactor: convert LineZone docstring example to doctest Apr 8, 2026
@Borda Borda self-requested a review April 8, 2026 12:35
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77%. Comparing base (48035c1) to head (4468142).
⚠️ Report is 1 commits behind head on develop.

❌ 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:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Borda Borda added the enhancement New feature or request label Apr 8, 2026
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:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vincenzonetti lets tkeep this pattern and in the docstring create trivial generators which created, for example, an empty file frames

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +55 to +61
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(
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +62 to +67
... 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)
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
... 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

Copilot uses AI. Check for mistakes.
@vincenzonetti vincenzonetti requested a review from SkalskiP as a code owner April 8, 2026 20:45
@vincenzonetti vincenzonetti requested a review from Borda April 9, 2026 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request waiting for author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants