docs: convert fenced examples to doctests in dataset/formats/createml.py (#2475)

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Swapnil Gautam 2026-08-07 12:12:40 -04:00 committed by GitHub
parent fb22686a5e
commit 7d325d23e3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 31 additions and 28 deletions

View File

@ -77,21 +77,23 @@ def createml_annotations_to_detections(
``"label"``, or any coordinate sub-key), or if a coordinate value
cannot be converted to float.
Examples:
```python
import supervision as sv
from supervision.dataset.formats.createml import (
createml_annotations_to_detections,
)
Example:
```pycon
>>> from supervision.dataset.formats.createml import (
... createml_annotations_to_detections,
... )
>>> annotations = [
... {
... "label": "dog",
... "coordinates": {"x": 50, "y": 50, "width": 20, "height": 20},
... }
... ]
>>> detections = createml_annotations_to_detections(annotations, {"dog": 0})
>>> detections.xyxy
array([[40., 40., 60., 60.]], dtype=float32)
>>> detections.class_id
array([0])
annotations = [
{
"label": "dog",
"coordinates": {"x": 50, "y": 50, "width": 20, "height": 20},
}
]
detections = createml_annotations_to_detections(annotations, {"dog": 0})
# detections.xyxy → [[40, 40, 60, 60]]
```
"""
if not image_annotations:
@ -240,20 +242,21 @@ def detections_to_createml_annotations(
Raises:
ValueError: If ``detections.class_id`` is ``None``.
Examples:
```python
import numpy as np
import supervision as sv
from supervision.dataset.formats.createml import (
detections_to_createml_annotations,
)
Example:
```pycon
>>> import numpy as np
>>> import supervision as sv
>>> from supervision.dataset.formats.createml import (
... detections_to_createml_annotations,
... )
>>> detections = sv.Detections(
... xyxy=np.array([[40, 40, 60, 60]], dtype=np.float32),
... class_id=np.array([0], dtype=int),
... )
>>> detections_to_createml_annotations(detections, classes=["dog"])
[{'label': 'dog', 'coordinates':
{'x': 50.0, 'y': 50.0, 'width': 20.0, 'height': 20.0}}]
detections = sv.Detections(
xyxy=np.array([[40, 40, 60, 60]], dtype=np.float32),
class_id=np.array([0], dtype=int),
)
detections_to_createml_annotations(detections, classes=["dog"])
# [{"label": "dog", "coordinates": {"x": 50.0, "y": 50.0, ...}}]
```
"""
class_ids = detections.class_id
@ -301,7 +304,7 @@ def save_createml_annotations(
ValueError: If two image paths share the same basename and would map to
the same CreateML ``image`` entry.
Examples:
Example:
```python
import supervision as sv
from supervision.dataset.formats.createml import save_createml_annotations