Skip to content

fix(metadata): blank Date/DateTime mean in summary-stats CSV (rebases #254)#295

Merged
jqnatividad merged 1 commit into
mainfrom
date-mean-fix
May 16, 2026
Merged

fix(metadata): blank Date/DateTime mean in summary-stats CSV (rebases #254)#295
jqnatividad merged 1 commit into
mainfrom
date-mean-fix

Conversation

@jqnatividad

Copy link
Copy Markdown
Collaborator

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`:

  • Date + DateTime rows blanked; numeric preserved
  • No Date rows → no rewrite, returns the original path (verifies short-circuit)
  • Already-empty mean → no rewrite

Verified locally in `dpp-test`: 98/98 unit tests pass (95 prior + 3 new).

Closes #254.

Test plan

🤖 Generated with Claude Code

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>
@jqnatividad jqnatividad merged commit 8cd0f34 into main May 16, 2026
1 check passed
@jqnatividad jqnatividad deleted the date-mean-fix branch May 16, 2026 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant