Repository navigation
fix: write array-valued data to CSV as parseable lists - #2707
Merged
Merged
Conversation
CSVSink passed NumPy arrays from Detections.data and custom_data to csv.writer, which calls str(). Arrays of more than 1000 elements were abbreviated with "...", smaller ones were space separated without commas, and 2-D arrays such as oriented-box corners spanned several lines. Arrays with ndim > 0 are now written as json.dumps(array.tolist()), the same values JSONSink emits. Scalars, strings, 0-d arrays, lists, tuples, dicts and arrays JSON cannot represent keep their previous output.
avanish-garg
force-pushed
the
fix/csv-sink-array-data
branch
from
October 8, 2026 20:21
3166e04 to
25d6475
Compare
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The focused implementation matches the stated behavior and has comprehensive regression coverage.
0 open findings
What changed in this PR
Fixes CSVSink to preserve array-valued detection data as parseable JSON.
Changes:
- Serializes non-scalar NumPy arrays with
json.dumps(value.tolist()). - Adds round-trip and regression coverage.
- Documents the behavior change.
| File | Description |
|---|---|
src/supervision/detection/tools/csv_sink.py |
Adds array cell formatting. |
tests/detection/test_csv.py |
Tests serialization and compatibility. |
docs/changelog.md |
Records the fix. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Changes: - Integrate fetched develop tip 8b94622 into the PR branch, carrying its 47-file target change set. - Preserve both target Unreleased entries and PR roboflow#2707's CSV array-data entry while resolving the changelog conflict. Impact: - Bring the PR branch current with the target's dataset, depth, metrics, documentation, and configuration work. - Keep the CSV fix and its regression tests intact on the integrated branch. Verification: - .venv/bin/python -m pytest -p no:xdist tests/detection/test_csv.py: 39 passed. - git diff --cached --check: clean; no unmerged paths remain. - Reviewed merge index tree 335245b and verified its first-parent path set matches fetched develop. Residual limits: - The requested assessed review report is unavailable (missing-matching-review-report); current PR metadata still says REVIEW_REQUIRED. --- Co-authored-by: Codex <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #2707 +/- ##
=======================================
Coverage 93% 93%
=======================================
Files 83 83
Lines 13109 13073 -36
=======================================
- Hits 12253 12220 -33
+ Misses 856 853 -3 🚀 New features to boost your workflow:
|
Changes: - Keep NumPy object-array values in CSV fallback when JSON conversion raises TypeError or ValueError. - Add a circular object-array regression spanning two detection rows. Impact: - CSVSink.append can write circular array values using csv.writer string conversion instead of aborting. - Serializable arrays and existing unsupported-type handling keep their established behavior. Verification: - The circular-array regression failed before the fix and passed after it; tests/detection/test_csv.py passed (40 tests). - Canonical gates passed: lint, formatting, mypy, full suite (5,440 passed, 79 skipped), and diff check. Residual limits: - Requested independent review coverage and historical source-context separation remain unresolved. - This commit does not claim independent review. --- Co-authored-by: Codex <[email protected]>
Borda
approved these changes
Oct 12, 2026
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.
Description
sv.CSVSinkwrote NumPy arrays fromdetections.data/custom_datathrough numpy'sstr(): a 1536-dfloat32 embedding came out as a summarised string with an ellipsis (6 of 1536 values recoverable) and OBB
corner arrays contained newlines.
Minimal repro (full script in the issue):
embeddingcell is'[0.8506242 0.63696164 ... 0.91254586'andjson.loadsfails.Motivation and Context
Embeddings and OBB corners are common in
data, andJSONSinkalready writes them correctly.Closes #2706
Changes Made
CSVSink._format_cell, applied whereappend()writes each row: annp.ndarraywithndim > 0iswritten as
json.dumps(value.tolist()), i.e. the same valuesJSONSinkemits (default separators, one line).str()form instead of raising.their previous output (existing tests pin them);
parse_detection_dataand_slice_valueare untouched.Testing
Ran (not the whole suite, not
pre-commit --all-files):pytest tests/detection/tools tests/detection/test_csv.py: 182 passed, 1 skipped.pytest --doctest-modules src/supervision/detection/tools/csv_sink.py: 1 passed.ruff check,ruff format --checkandmypy(strict) oncsv_sink.py: clean.mypyon the tests (the repo config ignores them).New
TestCSVSinkArrayData(11 cases): 1536-d float32 exact round trip, OBB corners without newlines, int /bool / str / empty arrays, NaN/inf, a broadcast array, complex fallback, unchanged scalar/string output and
consistency with
JSONSink. Ondevelop: 8 failed, 3 passed (the 3 are regression cases that must stayunchanged); with this change: 11 passed.
docs/changelog.mdunderUnreleased(skip for lint/type/format-only or pure doc changes)(Tick the first box only after you run the full suite yourself.)
Additional Notes
tolist(), so they are written as the exact double (0.6369617 becomes0.6369616389274597): about 31 KB per 1536-d embedding, roughly twice the shortest float32 repr, but identical
to JSONSink and exactly round-trippable.
NaN/Infinity/-Infinity, as JSONSink does; Python's json parses them, strictJSON parsers do not.
change existing pinned test output).