fix: replace deprecated 2-D np.cross with explicit determinant - #2386
Merged
Borda merged 5 commits intoJul 2, 2026
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #2386 +/- ##
=======================================
Coverage 84% 84%
=======================================
Files 70 70
Lines 10003 10004 +1
=======================================
+ Hits 8435 8436 +1
Misses 1568 1568 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR removes reliance on NumPy’s deprecated 2-D np.cross(a, b) behavior by replacing it with an explicit 2-D determinant expression, eliminating DeprecationWarning spam on NumPy 2.x and preventing a future hard failure when that path is removed upstream (Issue #2384).
Changes:
- Replace
np.cross(polygon, shift_polygon)inget_polygon_centerwith the explicit 2-D determinant. - Replace
np.cross(vector_at_zero, anchors - vector_start)incross_productwith the explicit 2-D determinant (and factor outdiff).
Review Scores (n/5):
- Code quality: 5/5
- Testing: 3/5
- Documentation: 4/5
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/supervision/geometry/utils.py | Replaces the 2-D np.cross centroid signed-area computation with an explicit determinant to avoid NumPy 2.x deprecation warnings. |
| src/supervision/detection/utils/internal.py | Replaces the 2-D np.cross in cross_product with an explicit determinant (hot path for LineZone.trigger). |
…tests - Add filterwarnings = ["error::DeprecationWarning"] to pyproject.toml so future np.cross 2-D reintroductions fail CI immediately (closes roboflow#2384) - Add test_get_polygon_center_no_deprecation_warning: asserts no DeprecationWarning from get_polygon_center (Copilot inline comment) - Add test_cross_product_no_deprecation_warning: asserts no DeprecationWarning from cross_product (Copilot inline comment) - Add test_cross_product_sign (4 parametrised cases): above / below / on-line / offset-start — directly tests the inline determinant correctness - Improve cross_product docstring: blank line after summary, adds Examples section with correct output, notes NumPy 2.0 rationale --- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Keeps both test approaches in tests/geometry/test_utils.py: - test_get_polygon_center_no_deprecation_warning (DeprecationWarning check) - test_get_polygon_center_does_not_call_np_cross (monkeypatch by contributor) --- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Borda
approved these changes
Jul 2, 2026
Draft
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
(https://google.github.io/styleguide/pyguide.html#383-functions-and-methods)
Description
np.cross(a, b) on 2-D vectors is deprecated in NumPy 2.0 and prints a
DeprecationWarning on every call. Two supervision call sites hit it:
polygon.
times per LineZone.trigger call.
Under pytest -W error::DeprecationWarning the current suite errors during
collection at tests/detection/test_polygon_zone_annotator.py.
For 2-D inputs np.cross(a, b) equals a[..., 0] * b[..., 1] - a[..., 1] *
b[..., 0] bit-exact. This PR swaps both call sites for the inline expression.
Type of Change
Motivation and Context
Fixes the DeprecationWarning fired on every sv.LineZone.trigger and
sv.get_polygon_center call on NumPy 2.x. pyproject.toml allows numpy>=1.21.2
with no upper bound. When NumPy removes the 2-D np.cross code path, the
affected APIs will hard-crash instead of just warning.
Closes #2384
Changes Made
explicit 2-D determinant.
with the explicit 2-D determinant.
Testing
feature works
Existing suite: 2288 passed, 1 skipped, no regressions. The suite now also
passes under pytest -W error::DeprecationWarning, which errored during
collection before this PR. Happy to add a regression test asserting no
DeprecationWarning on the two paths if that's the preferred direction.
Additional Notes
No public API changes or dependencies. Diff is 7 insertions, 2 deletions
across the two files.