fix(metadata): blank Date/DateTime mean in summary-stats CSV (rebases #254)#295
Merged
Conversation
Fixes the COPY failure reported in #254 by @avdata99: Error: invalid input syntax for type double precision: "2025-03-01" CONTEXT: COPY <stats-table>, line 7, column mean: "2025-03-01" Root cause: qsv reports a Date / DateTime column's ``mean`` as an ISO-formatted date string (the average day across the column), but the summary-statistics table declares ``mean FLOAT`` — so a direct COPY trips a type-mismatch error and the whole stats load aborts. Surfaces on any resource whose schema has a Date or DateTime column. Fix: a new ``MetadataStage._blank_date_means`` helper rewrites the qsv stats CSV with the ``mean`` cell blanked on Date / DateTime rows BEFORE the COPY. The numeric mean for actual numeric fields is preserved untouched. When no Date/DateTime rows are present the helper short-circuits and returns the original path so the common all-numeric case doesn't pay the cost of a spurious tempfile. Originally proposed in #254 against the pre-migration ``jobs.py``; this PR carries the equivalent fix into the new ``jobs/stages/metadata.py`` location, refactored as a method on ``MetadataStage`` (rather than inline) so the logic is unit- testable. ## Tests Three new cases in ``tests/test_metadata_stats_cleanup.py``: * Date + DateTime rows get their ``mean`` blanked; numeric rows pass through unchanged. * No Date rows → no rewrite, returns the original path (verifies the short-circuit). * Date row with already-empty ``mean`` → no rewrite needed. Verified locally in ``dpp-test``: **98/98 unit tests pass** (95 prior + 3 new). Closes #254. Co-Authored-By: @avdata99 Co-Authored-By: Claude Opus 4.7 (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.
Summary
Fixes the COPY failure reported in #254 by @avdata99:
```
Error: invalid input syntax for type double precision: "2025-03-01"
CONTEXT: COPY , line 7, column mean: "2025-03-01"
```
Root cause
qsv reports a Date / DateTime column's `mean` as an ISO-formatted date string (the average day across the column), but the summary-statistics table declares `mean FLOAT` — direct COPY trips a type mismatch and the whole stats load aborts. Surfaces on any resource whose schema has a Date or DateTime column.
Fix
A new `MetadataStage._blank_date_means` helper rewrites the qsv stats CSV with the `mean` cell blanked on Date / DateTime rows BEFORE the COPY. Numeric-field means are preserved. When no Date/DateTime rows are present, the helper short-circuits and returns the original path so the common all-numeric case doesn't pay the cost of a spurious tempfile.
Rebase vs #254
#254 added the cleanup inline in the pre-migration `jobs.py`. This PR carries the equivalent fix into the new `jobs/stages/metadata.py` location, refactored as a method on `MetadataStage` so it's unit-testable.
Tests
Three new cases in `tests/test_metadata_stats_cleanup.py`:
Verified locally in `dpp-test`: 98/98 unit tests pass (95 prior + 3 new).
Closes #254.
Test plan
🤖 Generated with Claude Code