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

Get a dataframe of nodeId and nodeLabel in absence of any other node properties #666

Open
Hossein-Tohidi opened this issue Jun 24, 2024 · 4 comments

Comments

@Hossein-Tohidi
Copy link

Looking for a function that generates a dataframe consisting of nodeId and nodeLabel
When the graph does not have any node attributes (just nodeId and nodeLabels are present), I cannot find a way to get the nodeLabels back. The nodeProperties.stream returns an empty dataframe. (This is working fine when we do have any node properties).

nodes_df = gds.graph.nodeProperties.stream(G, list(node_props), listNodeLabels=True)

Additionally, G.node_labels() only produces a list of labels without mapping them to the corresponding nodeIds. I checked the G._graph_info dictionary as well, but the map does not seem to be stored there.

For edges, we have gds.graph.relationships.stream and gds.graph.relationshipProperties.stream, which support retrieving edges with or without properties. However, I couldn't find similar functionalities for nodes.

@adamnsch
Copy link
Contributor

adamnsch commented Jun 25, 2024

Hi @Hossein-Tohidi,

Thank you for the feature request.

We are aware of this limitation, and there will likely be a new feature that will let you do what you're asking before too long. Until then, would you perhaps be able to project your graph with some dummy node property with a default value? If all nodes use the default value for a property, virtually no extra memory will be used for that node property. So it should not impact performance and so on (except slightly when doing gds.graph.nodeProperties.stream).

Hope this was helpful,
Adam

@Hossein-Tohidi
Copy link
Author

Thanks @adamnsch, unfortunately, that workaround might not work in our wrapper function (a utility function that enables communication to Neo4j/GDS) for two reasons. 1- We dont know in advance whether or not the user of the wrapper function will or will not specify any node property to be returned (the graph might be constructed by directly using a GDS functionalities, and not through the wrapper function) 2- Modifying the graph seems not possible (adding a node property to an already created gds graph object, without recreating it).

@Hossein-Tohidi
Copy link
Author

Hossein-Tohidi commented Jun 25, 2024

I was able to run one algorithm on the graph like louvain to mutate the graph by adding a node property and at the end drop that property. It might not be ideal but it works.

@adamnsch
Copy link
Contributor

@Hossein-Tohidi I see

I was able to run one algorithm on the graph like louvain to mutate the graph by adding a node property and at the end drop that property. It might not be ideal but it works.

That's an interesting workaround. If you find that Louvain takes a while to run, you could use a linear complexity algorithm like degree centrality instead. Anyway, it sounds like you're unblocked for now which is good. We'll let you know when we launch the aforementioned feature that will allow you to skip using the workaround.

Thanks,
Adam

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants