Skip to content

cd_trend(): typed zero-row table when no series is long enough - #110

Merged
NewGraphEnvironment merged 5 commits into
mainfrom
101-cd-trend-no-series-long-enough-gives-a-0
Sep 30, 2026
Merged

NewGraphEnvironment merged 5 commits into
mainfrom
101-cd-trend-no-series-long-enough-gives-a-0

Conversation

@NewGraphEnvironment

Copy link
Copy Markdown
Owner

Summary

  • cd_trend() now returns a zero-row tibble with its full column set when no combination has 3+ years, instead of a shapeless 0 x 0. cd_summary() on it returns an empty table (it used to fail with Column 'period' not found), and cd_plot_timeseries() no longer warns about uninitialised columns.
  • The template's key types come from the same expand.grid the rows are built from, so a factor variable/period stays a factor and trend_start = NULL keeps its column. slope/intercept lose zyp's "yr"/"Intercept" names, so empty and full results share one ptype.
  • @return in ?cd_trend documents the empty shape; CLAUDE.md notes it on the trend-table contract.

Fixes #101

Related Issues

  • Relates to NewGraphEnvironment/sred-2025-2026#23

Test plan

Notes

  • Behaviour change: names(trn$slope) / names(trn$intercept) are now NULL. Nothing in the repo reads them.
  • The existing short-series test asserted only nrow == 0, which the 0 x 0 already satisfied. That is why this went uncaught.

🤖 Generated with Claude Code

https://claude.ai/code/session_01GignjoKpZADXywTf6pAMgj

NewGraphEnvironment and others added 5 commits September 30, 2026 10:50
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GignjoKpZADXywTf6pAMgj
cd_trend() dropped every combination with fewer than 3 years, and
bind_rows() of all-NULL is a 0 x 0 tibble, so cd_summary() died on
"Column `period` not found" and cd_plot_timeseries() warned about
uninitialised columns. Rows are now bound under a zero-row template
whose key types come from the same expand.grid the rows are built from,
so a factor variable stays a factor and trend_start = NULL keeps its
column. slope and intercept are unnamed so empty and full results share
one ptype.

Fixes #101

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
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GignjoKpZADXywTf6pAMgj
@NewGraphEnvironment
NewGraphEnvironment merged commit 8a7d1b9 into main Sep 30, 2026
1 check passed
@NewGraphEnvironment
NewGraphEnvironment deleted the 101-cd-trend-no-series-long-enough-gives-a-0 branch September 30, 2026 18:13
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_trend(): no series long enough gives a 0x0 tibble, and cd_summary() errors on it

1 participant