Skip to content

cd_anomaly() and the consumer chain: accept series outside cd_variables() - #94

Merged
NewGraphEnvironment merged 5 commits into
mainfrom
92-cd-anomaly-series-outside-cd-variables
Sep 29, 2026
Merged

NewGraphEnvironment merged 5 commits into
mainfrom
92-cd-anomaly-series-outside-cd-variables

Conversation

@NewGraphEnvironment

Copy link
Copy Markdown
Owner

Summary

  • cd_anomaly() resolves anomaly_type, unit (the anomaly's unit, same meaning as cd_variables()$unit) and long_name from the input where present, falling back to cd_variables() row by row. A variable whose type can't be resolved is now an error naming it, not a silent NA. Contract documented under "Input contract" in ?cd_anomaly, with a runnable non-ERA5 example.
  • cd_trend() carries long_name through, plus anomaly_type/unit when trending anomalies (not raw values, where the anomaly unit would mislabel the slope). cd_summary() uses them, then the registry, then the variable name.
  • One row per (variable, period, year) is enforced in cd_baseline, cd_anomaly, cd_compare, cd_trend, so two stations stacked under one variable are refused instead of pooled. Grouped input is accepted. The rules live in three shared helpers in R/cd_anomaly.R (series_check, meta_resolve, meta_check).

Behaviour changes for existing callers

  • Input that used to return NA anomalies now errors.
  • Input with duplicate (variable, period, year) rows used to be pooled silently; it now errors. All committed vignette series have 0 duplicates.
  • cd_trend(cd_anomaly(...)) output has two extra columns (anomaly_type, unit).

Suggest a minor bump at merge.

Related Issues

Test plan

  • devtools::test(): 278 pass, 0 fail (2 warnings are pre-existing, in test-cd_plot_comparison.R)
  • 21 mutations, one per new guard and chain-caller check, each turn a test red
  • ERA5 path unchanged: the regional Peace and Kootenay cd_trend(ano) reproduce the committed trn exactly, and cd_summary() output is identical
  • pkgdown CI. pkgdown::check_pkgdown() fails locally on main as well (DESCRIPTION URL), and no exports were added

Notes

Review: one plan review and three code-check rounds found 10 issues and all were fixed. Two sat inside earlier fixes. The last was a plain ungroup() that turned station-grouped input from an error into silent pooling. The loop ended by enumerating every export against the shared helpers, not on a clean round. Details are in planning/archive/2026-09-issue-92-series-outside-cd-variables/.

Known and not fixed, both pre-existing: cd_trend() on zero rows returns a tibble with no columns, and a series with no baseline row still gets anomaly = NA.

🤖 Generated with Claude Code

https://claude.ai/code/session_01GignjoKpZADXywTf6pAMgj

NewGraphEnvironment and others added 5 commits September 28, 2026 21:27
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GignjoKpZADXywTf6pAMgj
Relates to #92

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GignjoKpZADXywTf6pAMgj
cd_anomaly() takes anomaly_type, unit (the anomaly's unit) and long_name
from the input where present, falling back to cd_variables() row by row,
and aborts on a type it cannot resolve instead of returning NA. cd_trend()
carries the metadata through and cd_summary() uses it. One row per
variable/period/year is now enforced across cd_baseline, cd_anomaly,
cd_compare and cd_trend, so stacked stations are refused rather than
pooled; grouped input is accepted.

Fixes #92

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GignjoKpZADXywTf6pAMgj
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GignjoKpZADXywTf6pAMgj
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GignjoKpZADXywTf6pAMgj
@NewGraphEnvironment
NewGraphEnvironment merged commit 1462093 into main Sep 29, 2026
1 check passed
@NewGraphEnvironment
NewGraphEnvironment deleted the 92-cd-anomaly-series-outside-cd-variables branch September 29, 2026 05:18
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.

cd_anomaly() and cd_summary(): accept series outside cd_variables() instead of returning NA

1 participant