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

gds.graph.construct replace existing projection #655

Open
Mintactus opened this issue Jun 1, 2024 · 3 comments
Open

gds.graph.construct replace existing projection #655

Mintactus opened this issue Jun 1, 2024 · 3 comments

Comments

@Mintactus
Copy link

For testing purposes, having a replace parameter for gds.graph.construct would be really great.
Set to false by default, when true the existing projection is replaced if there is one.

@Mats-SX Mats-SX transferred this issue from neo4j/graph-data-science Jun 3, 2024
@Mats-SX
Copy link
Contributor

Mats-SX commented Jun 3, 2024

Hello @Mintactus and thank you for this feature request!

While we understand how this parameter could make sense in some use cases, we want to point out that it is very easy to drop a projected graph. There are multiple ways to do this with minimal Python code:

Use the graph as a context manager:

with gds.graph.construct('g', nodes, rels) as G:
    result = gds.wcc.stream(G)

# G is dropped when the context ends

Use the drop() method on the graph object:

G = gds.graph.construct('g', nodes, rels)
result = gds.wcc.stream(G)
G.drop()

Use the gds.graph.drop() endpoint as a post-cleanup:

G = gds.graph.construct('g', nodes, rels)
result = gds.wcc.stream(G)
gds.graph.drop(G)

Use the gds.graph.drop() endpoint as a pre-cleanup:

gds.graph.drop('g', failIfMissing=False)
G = gds.graph.construct('g', nodes, rels)
result = gds.wcc.stream(G)

I hope these alternatives will cover your use cases without the need for an additional parameter.

All the best
Mats

@Mintactus
Copy link
Author

Since I'm building the graph from a dataframe, and running the same ETL process multiple times, I can't use these options because the graph object doesn't exist yet ( unless I create it using get) , but the projection does because of the previous iteration.

It looks like this...

create_markov_chain_nodes()
create_markov_chain_relationships()
drop_the_existing_projection()
project_markov_chain_graph() <- Just do it! Don't care about existing data

In general, I would say it's really great to have Idempotent workflows for massive tests purpose

@Mats-SX
Copy link
Contributor

Mats-SX commented Jun 11, 2024

As I showed above, it is not necessary to have a graph object to drop the graph. You can use just the graph name. If you do not know the graph name (because it is randomly generated or something), you can drop all graphs by using gds.graph.list() followed by gds.graph.drop().

As far as I understand, the workflow you show with the drop_the_existing_projection() is an idempotent setup already. Am I missing something?

Mats

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

2 participants