feat: Add attribute combination support to graph operators#2676
feat: Add attribute combination support to graph operators#2676schochastics wants to merge 14 commits into
Conversation
…tion, compose, disjoint_union)
|
devtools::document() doesnt work locally for me |
| ############# | ||
|
|
||
| igraph.i.attribute.combination <- function(comb) { | ||
| igraph.i.attribute.combination <- function(comb, allow_rename = FALSE) { |
There was a problem hiding this comment.
Split into two functions, one for a scalar, and the list function as a simple wrapper?
| default_comb <- if (length(default_idx) > 0) { | ||
| comb[[default_idx[1]]] | ||
| } else { | ||
| "rename" |
There was a problem hiding this comment.
| "rename" | |
| # Backward-compatible standard | |
| "rename" |
| ################################################################### | ||
|
|
||
| rename.attr.if.needed <- function( | ||
| combine.attrs <- function( |
There was a problem hiding this comment.
Keep rename_attr_if_needed() and use it only for those attributes where the action is "rename"?
|
This is how benchmark results would change (along with a 95% confidence interval in relative change) if c26ab02 is merged into main:
|
…lper Address review feedback on #2676: - Rename the new graph.attr.comb/vertex.attr.comb/edge.attr.comb arguments of union()/intersection()/compose()/disjoint_union() to snake_case (these args are new in this PR, so no deprecation is needed). - Extract rename_attr_if_needed() back out of combine.attrs() for the "rename" strategy, preserving the historical overwrite-on-clash semantics under chains of %du%. - Add a clarifying comment on the backward-compatible "rename" default. - Move the make_named_pair() test helper into helper.R. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…tted names Follow-up to review feedback on #2676 ("clean up edge.attr.comb"): - simplify(), as_undirected() and contract() gain snake_case edge_attr_comb / vertex_attr_comb arguments via the argument-migration infrastructure (tools/migrations.R). The old dotted names still work and emit a single lifecycle::deprecate_soft() warning. - Rename the matching igraph option keys edge.attr.comb -> edge_attr_comb and vertex.attr.comb -> vertex_attr_comb, with back-compatible aliasing in igraph_opt()/igraph_options(); the dotted keys still read and set, soft- deprecated. Update the stimulus codegen default (types-RR.yaml) and the regenerated *_impl defaults to match. Deprecated wrappers (as.undirected(), contract.vertices()) are left frozen; their snapshot now records the resulting layered deprecation warnings. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
This is how benchmark results would change (along with a 95% confidence interval in relative change) if b58da44 is merged into main:
|
| "vertex_attr_comb" = list(name = "concat", "ignore"), | ||
| "edge_attr_comb" = list(weight = "sum", name = "concat", "ignore"), |
…e combination in operators
The `graph_attr_comb` parameter in `union()`, `intersection()`, `disjoint_union()`, and `compose()` now defaults to `igraph_opt("graph_attr_comb")` (which is `"rename"` by default) instead of a hard-coded `"rename"`. This allows users to globally configure graph attribute combination behavior via `igraph_options()`.
|
This is how benchmark results would change (along with a 95% confidence interval in relative change) if 6d94668 is merged into main:
|
|
@maelle it is now |
|
This is how benchmark results would change (along with a 95% confidence interval in relative change) if a85a78c is merged into main:
|
|
Yay 🎉 |
| cli::cli_warn("Some attributes are duplicated") | ||
| } | ||
| known_names <- c( | ||
| "ignore", |
| "median", | ||
| "concat" | ||
| ) | ||
| known_codes <- c(0, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12) |
There was a problem hiding this comment.
add an explanatory comment?
Also, do we use explicit integers?
And would there be a way to define each code beside its name?
| if (is.na(x)) { | ||
| idx <- pmatch(tolower(x), known_names) | ||
| if (is.na(idx)) { | ||
| if (!allow_rename && identical(tolower(x), "rename")) { |
There was a problem hiding this comment.
It'd be more logical to me to invert the two
if (identical(tolower(x), "rename") && !allow_rename) {| if (is.na(idx)) { | ||
| if (!allow_rename && identical(tolower(x), "rename")) { | ||
| cli::cli_abort( | ||
| "{.val rename} is only supported by graph operators ({.fn union}, {.fn intersection}, {.fn compose}, {.fn disjoint_union}), not by this function." |
There was a problem hiding this comment.
Rephrase to
- Can't use rename with function X (possible to add its name)
- Hint: rename is only supported by blablabla
| #' | ||
| #' The functions that support the combination of attributes have one or two | ||
| #' extra arguments called `vertex.attr.comb` and/or `edge.attr.comb` | ||
| #' extra arguments called `vertex_attr_combine` and/or `edge_attr_combine` |
There was a problem hiding this comment.
Seeing a clear name makes me so happy 😭 🪮
| #' graph operators [union()], [intersection()], [compose()] and | ||
| #' [disjoint_union()] and preserves their historical behaviour. | ||
| #' Only those operators accept `"rename"`; [simplify()] and | ||
| #' [contract()] will reject it because the rename strategy has no |
There was a problem hiding this comment.
this sentence could be clarified: "it's hard to know where each attribute came from" or so?
| `as.undirected()` was deprecated in igraph 2.1.0. | ||
| i Please use `as_undirected()` instead. | ||
| Warning: | ||
| The igraph option `edge.attr.comb` was deprecated in igraph 3.0.0. |
| u <- union( | ||
| gs$g1, | ||
| gs$g2, | ||
| vertex_attr_combine = list(weight = "sum", "rename") |
There was a problem hiding this comment.
add expectation on weight sum here too?
|
|
||
| test_that("union() picks first non-NA when only one input has the attr", { | ||
| gs <- make_named_pair() | ||
| u <- union(gs$g1, gs$g2, vertex_attr_combine = "first", byname = TRUE) |
There was a problem hiding this comment.
why byname and not by_name?
|
|
||
| # Default option ("rename") preserves the historical suffixing behaviour. | ||
| u <- union(g1, g2) | ||
| expect_true(all(c("label_1", "label_2") %in% graph_attr_names(u))) |
fix #57