Re-verify remaining supervision review backlog against develop HEAD; most items were already resolved by an intervening commit, only genuinely-open gaps got new fixes. Fix float32 precision loss in box_iou_batch for large coordinates (GeoTIFF-scale) by accumulating in float64. Raise ValueError instead of a strippable assert in EvaluationDataset.load_predictions for unknown image ids. Add HeatMapAnnotator.reset() to clear accumulated heat for annotator reuse. Add missing coverage: labelme export basename collisions, _greedy_match matcher, metrics.core ABC/enum contracts, metrics.utils.utils pandas guard; remove a global RNG-seed pollution site in a metrics test. Document the last two undocumented public exports (calculate_masks_centroids, is_compressed_rle) and add usage examples to 17 previously-example-less public functions/classes (NMS/NMM helpers, draw utils, PolygonZoneAnnotator, mask/polygon converters). * tests: load_predictions ValueError branch + empty-dataset coverage * fix: box_iou_batch int-dtype overflow, narrow float32 precision claim * feat: add reset() to TraceAnnotator/DetectionsSmoother, fix docstrings * docs: fix temp file leak in coco.py docstring, rename misnamed test --------- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: OpenAI Codex <codex@openai.com>
45 lines
1.6 KiB
Python
45 lines
1.6 KiB
Python
"""Tests for supervision.metrics.utils.utils — pandas extra guard."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import builtins
|
|
|
|
import pytest
|
|
|
|
from supervision.metrics.utils.utils import ensure_pandas_installed
|
|
|
|
|
|
class TestEnsurePandasInstalled:
|
|
"""Verify the `metrics` extra guard for pandas-dependent code paths."""
|
|
|
|
def test_noop_when_pandas_importable(self, monkeypatch: pytest.MonkeyPatch) -> None:
|
|
"""No exception is raised when pandas is importable."""
|
|
real_import = builtins.__import__
|
|
|
|
def _fake_import(name: str, *args: object, **kwargs: object) -> object:
|
|
"""Pretend pandas is importable regardless of the real environment."""
|
|
if name == "pandas":
|
|
return object()
|
|
return real_import(name, *args, **kwargs)
|
|
|
|
monkeypatch.setattr(builtins, "__import__", _fake_import)
|
|
|
|
ensure_pandas_installed()
|
|
|
|
def test_raises_import_error_when_pandas_missing(
|
|
self, monkeypatch: pytest.MonkeyPatch
|
|
) -> None:
|
|
"""A clear ImportError is raised when pandas cannot be imported."""
|
|
real_import = builtins.__import__
|
|
|
|
def _fake_import(name: str, *args: object, **kwargs: object) -> object:
|
|
"""Raise ImportError for pandas, delegate everything else."""
|
|
if name == "pandas":
|
|
raise ImportError("No module named 'pandas'")
|
|
return real_import(name, *args, **kwargs)
|
|
|
|
monkeypatch.setattr(builtins, "__import__", _fake_import)
|
|
|
|
with pytest.raises(ImportError, match=r"metrics.*extra"):
|
|
ensure_pandas_installed()
|