Skip to content

1155: List duplicated forecast units in the duplicate-forecast error - #1246

Draft
nikosbosse wants to merge 4 commits into
mainfrom
issue-1155-duplicates-in-message
Draft

nikosbosse wants to merge 4 commits into
mainfrom
issue-1155-duplicates-in-message

Conversation

@nikosbosse

@nikosbosse nikosbosse commented Nov 8, 2026 •

Copy link
Copy Markdown
Collaborator

CLAUDE:

Description

This PR closes #1155.

The duplicate-forecast error (raised by as_forecast_<type>() / assert_forecast() via the internal check_duplicates()) now lists the first few duplicated forecast units inline, so users can see what is wrong without a separate call to get_duplicate_forecasts(). The existing message and the get_duplicate_forecasts(...) hint are unchanged; the new part is appended. Example: one 23-quantile forecast from example_quantile duplicated once:

... to identify duplicate rows. Duplicated forecast units:
  - location = DE, target_end_date = 2021-05-08, target_type = Cases, location_name = Germany, forecast_date = 2021-05-03, model = EuroCOVIDhub-ensemble, horizon = 1 (46 rows).
  • Up to 5 units are shown, one per line, followed by ... and K more forecast unit(s) if there are more.
  • Each unit shows (N rows): the number of rows involved in the duplication for that unit, original rows included, across all quantile levels / samples (so one exact duplicate of a 23-quantile forecast gives 46). This count goes slightly beyond what the issue thread agreed on (listing the units); it is cheap and tells the user how many rows to look at, but it can be dropped if maintainers prefer.
  • The counts come from the duplicates table that check_duplicates() has already computed, so get_duplicate_forecasts() runs only once.

Implementation: two independent drafts were compared by a judge agent; draft B was chosen as base. One improvement was taken from the comparison: the counts reuse the existing duplicates table instead of calling get_duplicate_forecasts() a second time.

Checklist

  • My PR is based on a package issue and I have explicitly linked it.
  • I have included the target issue or issues in the PR title as follows: issue-number: PR title
  • I have tested my changes locally. Full devtools::test() passes (0 failures, 0 errors).
  • I have added or updated unit tests where necessary. Four new tests in tests/testthat/test-get-duplicate-forecasts.R: one duplicated point unit with its count and no "more" line; seven duplicated units truncated to 5 plus "... and 2 more"; a duplicated 23-quantile forecast reporting (46 rows); and a regression test for data containing a column named fu. Verified they fail before and pass after the change: the first two fail against origin/main's R/get-duplicate-forecasts.R; the quantile and fu-column tests failed (5 failing expectations in total) against the previous commit of this PR, before the grouping fix and relabelling.
  • I have updated the documentation if required. The check_duplicates() description now mentions the listed units and what the count means (man/check_duplicates.Rd).
  • I have built the package locally and run rebuilt docs using roxygen2. Unrelated churn from the local roxygen2 version was reverted.
  • My code follows the established coding standards and I have run lintr::lint_package() to check for style issues introduced by my changes. I linted the changed files with lintr::lint(). The only hits are object_usage_linter "no visible binding/global function" false positives (the package was not installed), which also hit pre-existing code in the same file.
  • I have added a news item linked to this PR.
  • I have reviewed CI checks for this PR and addressed them as far as I am able. CI pending on the latest push; to be checked before marking ready.

Review

An independent adversarial agent reviewed the full diff. Changes made in response:

  • Grouping bug (major): the per-unit counts were grouped with by = fu, a bare symbol that data.table resolves as a column name first. Data with a column named fu merged all units into one bullet with blank values. Now by = c(fu), matching the idiom used in get_duplicate_forecasts(), with a regression test that failed before the fix.
  • Meaning of the count (minor): the label (N duplicated rows) read like "extra copies" although it includes the originals. It is now (N rows), and the roxygen/Rd and NEWS say it counts all rows involved, originals included. The earlier PR-description claim that the count separates an exact duplicate from a missing forecast-unit column was removed, since for quantile/sample forecasts an exact duplicate also gives a large count.
  • Test coverage (minor): added a quantile test asserting (46 rows) for one duplicated 23-quantile forecast, plus the fu-column regression test.
  • Grouping style (part of a minor point): both aggregations now use by = c(...).

Rebutted / not applied:

  • Factor the count into a shared helper (minor): not done. The aggregation is a single data.table expression, and get_duplicate_forecasts(counts = TRUE) would need a second full duplicate pass, which this PR deliberately avoids. A helper for a one-liner adds indirection without removing real duplication.
  • Shorten bullets by showing only varying columns (nit): not done; the reviewer agreed it adds complexity for little gain. Showing every forecast-unit column keeps each line self-contained. The always-true inherits(data, "forecast") branch is pre-existing and out of scope.
  • CI / lint items (nit): lint was run on the changed files (see checklist); CI will be checked before the PR is marked ready.

🤖 Generated with Claude Code

nikosbosse and others added 4 commits November 8, 2026 13:08
The duplicate-forecast error now lists up to five duplicated forecast
units with the number of duplicated rows for each, plus a count of any
further units, so users can diagnose the problem without a second call
to get_duplicate_forecasts().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Summarise the already-computed duplicates instead of calling
get_duplicate_forecasts() a second time, which avoided a repeated
grouping/sort and the setdiff() workaround for the count column.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Group with by = c(fu) so a data column named `fu` cannot hijack the
grouping, label the per-unit count as "(N rows)" and document that it
includes the original rows, and add tests for a quantile forecast and
for a `fu` column.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.19%. Comparing base (8b18f07) to head (e124e83).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1246   +/-   ##
=======================================
  Coverage   99.18%   99.19%           
=======================================
  Files          41       41           
  Lines        2333     2347   +14     
=======================================
+ Hits         2314     2328   +14     
  Misses         19       19           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
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.

Show duplicate forecast summary in check_duplicates() error message

1 participant