Skip to content

Fix cforest models under partykit 1.3-0 - #434

Merged
EmilHvitfeldt merged 1 commit into
mainfrom
fix-partykit-130-gettree
Aug 23, 2026
Merged

Fix cforest models under partykit 1.3-0#434
EmilHvitfeldt merged 1 commit into
mainfrom
fix-partykit-130-gettree

Conversation

@EmilHvitfeldt

Copy link
Copy Markdown
Member

main is currently red, and #433 inherited it. The cause is partykit 1.3-0, released in the last day or so, not anything in either PR.

Evidence it is pre-existing

  • main at 3bfa3c7 already fails: run 32607353890 reports processing vignette 'partykit.Rmd' failed.
  • Checking out unmodified main locally and installing partykit 1.3-0 reproduces the identical error. With partykit 1.2.27 it passes.
  • Give the unsupported-model error a condition class #432's own PR checks were green, and the failure appeared on the merge commit, which is the window the partykit release landed in.

The bug

partykit 1.3-0 added a shim to its S3 methods that warns when a method is called directly instead of through the generic. It identifies the caller with:

caller <- sys.call(-1)
if (is.null(caller) || as.name(as.list(caller)[[1L]]) != gfun) { ... }

as.name() errors on any call whose first element is not a symbol. The generic's own frame is the method's caller, so writing partykit::gettree(...) makes that first element the :: call, and every cforest model dies with:

'language' object cannot be coerced to type 'symbol'

Note is.null(caller) || short-circuits, which is why a bare top-level call looks fine and this only shows up from inside another function. It takes out tidypredict_fit(), parse_model(), and the partykit vignette, so R CMD check fails at vignette building rather than at tests.

Calling partykit::gettree() is correct usage, so this is an upstream regression. Worth reporting to partykit; this PR just unblocks us.

The fix

Bind the generic to a local name and call it through that symbol.

The name has to be gettree specifically. The shim compares the symbol it recovers against the generic's own name, so gettree stays silent while any other name works but emits a spurious "calling partykit methods directly is deprecated" warning on every call. I verified both branches of that.

Only gettree is affected. I checked every partykit function tidypredict calls with a :: prefix — nodeids, nodeapply, as.party, id_node, is.terminal, kids_node — and they are all fine.

Verification

Under partykit 1.3-0: suite FAIL 0 | WARN 6 | SKIP 1 | PASS 2475, and R CMD check with vignettes gives 0 errors, 0 warnings. The remaining notes are a worktree .git and the pre-existing unstated catboost in vignettes.

The new test asserts both halves of the fix: no error, and no warning, so a future refactor that renames the binding gets caught rather than silently reintroducing warning noise.

Worth merging ahead of #433, which should then go green on rebase.

partykit 1.3-0 added a shim to its S3 methods that warns when a method
is called directly rather than through the generic. It identifies the
caller with

  as.name(as.list(sys.call(-1))[[1L]])

which errors on any call whose first element is not a symbol. The
generic's own frame is the method's caller, so calling
`partykit::gettree(model, tree_no)` makes that first element the `::`
call, and every cforest model fails with

  'language' object cannot be coerced to type 'symbol'

This breaks tidypredict_fit(), parse_model() and the partykit vignette,
so R CMD check fails at vignette building.

Bind the generic to a local name and call it through that symbol. The
name has to be `gettree`, since the shim compares the symbol it recovers
against the generic's own name and only stays quiet when they match; any
other name works but emits a spurious deprecation warning per call.

Only gettree is affected. nodeids, nodeapply, as.party, id_node,
is.terminal and kids_node were each checked and are fine with the `::`
prefix.
@EmilHvitfeldt
EmilHvitfeldt merged commit 96d67c7 into main Aug 23, 2026
9 checks passed
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