Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression in edgelist import with as_tbl_graph #192

Closed
trifle opened this issue Apr 2, 2024 · 1 comment
Closed

Regression in edgelist import with as_tbl_graph #192

trifle opened this issue Apr 2, 2024 · 1 comment

Comments

@trifle
Copy link

trifle commented Apr 2, 2024

Hi, thanks for the wonderful tidygraph package.

I recently ran some code that was about a year old, and it ran into errors because tidygraph current (1.3.1) changed the behavior of as_tbl_graph() to no longer read name attributes from to and from columns of edgelists.

What seemed weird to me is that tbl_graph() works completely differently, reading the edgelist as node attributes.

# No names
> edges %>% as_tbl_graph()
# A tbl_graph: 290 nodes and 41905 edges
#
# A directed acyclic simple graph with 1 component
#
# Node Data: 290 × 0 (active)
#
# Edge Data: 41,905 × 3
   from    to  weight
  <int> <int>   <dbl>
1     1     2 0.00968

> edges %>% tbl_graph()
# A tbl_graph: 41905 nodes and 0 edges
#
# A rooted forest with 41905 trees
#
# Node Data: 41,905 × 3 (active)
       from        to  weight
      <dbl>     <dbl>   <dbl>
 1 112358  853211 0.00968
 2 112358 989898 0.00565

If this is intentional then I'm sorry for the superfluous report, but the changelog read to me as if there were some fixes lately related to similar issues.

@trifle
Copy link
Author

trifle commented Apr 3, 2024

So this was just a fluke from the edgelist which invalidated a join. Sorry for the noise!

The issue was that in order for vertex attributes to be set from an edgelist, they need to be character type, not dbl.
This is documented in https://tidygraph.data-imaginist.com/reference/tbl_graph.html:

A data.frame containing information about the nodes in the graph. If edges$to and/or edges$from are characters then they will be matched to the column named according to node_key in nodes, if it exists. If not, they will be matched to the first column.

Because I had persisted my edgelist to csv and my node names are numerical IDs, the columns were autocast to dbl.

@trifle trifle closed this as completed Apr 3, 2024
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

No branches or pull requests

1 participant