fix: drop dtype coercion in CSV update path - #1370
Open
davidberenstein1957 wants to merge 1 commit into
Open
Conversation
Updating a run row coerced each incoming value to the dtype pandas
inferred for the existing column. Columns empty in every row are read
back as float64, so numpy.float64("") / numpy.float64(None) raised.
Rebuild the row via concat instead, which dedupes by run_id without
touching dtypes.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1370 +/- ##
==========================================
+ Coverage 91.39% 91.42% +0.03%
==========================================
Files 49 49
Lines 5056 5051 -5
==========================================
- Hits 4621 4618 -3
+ Misses 435 433 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
davidberenstein1957
marked this pull request as ready for review
August 12, 2026 17:36
davidberenstein1957
added a commit
that referenced
this pull request
Aug 12, 2026
Rebased on fix/csv-update-dtype-coercion (#1370), which fixes the CSV dtype coercion properly, so the local workaround in file.py is dropped. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
What changed
FileOutput.out()inon_csv_write="update"mode no longer assigns the new values column by column withdf[col].dtype.type(val). The single-existing-row branch now drops the previous row for the run and re-appends the new one viapd.concat, which achieves the same dedupe-by-run_idwithout any dtype coercion. Thelen(df_run) > 1warning branch is unchanged, and the "no existing row" case falls out of the sameconcat(dropping nothing).Why
df[col].dtype.type(val)coerced each incoming value to whatever dtype pandas inferred when reading the existing CSV back. A column empty in every existing row is read back asfloat64, so this evaluatednumpy.float64("")ornumpy.float64(None)and raised.This is reachable today: an
OfflineEmissionsTrackerleaveslongitude/latitudeempty, andgpu_count/gpu_modelare empty on CPU-only machines. Any run writing twice (aflush()thenstop()) crashed on the second write withValueError: could not convert string to float: ''.Row ordering
The updated row now moves to the end of the file instead of staying in place. Rows are timestamped, so this only affects files where runs were interleaved.
Verification
test_file_output_out_update_with_always_empty_columnsfails onmasterwith theValueErrorabove and passes with this change.uv run pytest tests/output_methods/ -q— 48 passed.uv run pytest tests/test_emissions_tracker.py -q— 31 passed.uv run pre-commit run --files codecarbon/output_methods/file.py tests/output_methods/test_file.py— all hooks pass.Note: #1366 (SLURM) touches this same block incidentally; whichever lands second will need a rebase.
Closes #1367
🤖 Generated with Claude Code