using neo4j bolt helper with AWS neptune - element_id does not exist
DataBoyTX opened this issue · comments
Thomas Cook commented
Describe the bug
element_id is returned by neo4j, but neptune does not return this property, so need to use id field instead
To Reproduce
first:
!pip install --user neo4j
!pip install graphistry
then:
url='neptune-serverless-xyz.us-east-1.neptune.amazonaws.com'
from neo4j import GraphDatabase
uri = f"bolt://{url}:8182"
driver = GraphDatabase.driver(uri, auth=("ignored", "ignored"), encrypted=True)
graphistry.register(bolt=driver)
g = graphistry.cypher("MATCH (a)-[r]->(b) return a, r, b")
Expected behavior
should not error out but return the graph via bolt, but missing element_id from Neptune results
Actual behavior
error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[14], line 8
5 driver = GraphDatabase.driver(uri, auth=("ignored", "ignored"), encrypted=True)
7 graphistry.register(bolt=driver)
----> 8 g = graphistry.cypher("MATCH p=(a)-[r]->(b) return p limit 5")
File ~/anaconda3/envs/JupyterSystemEnv/lib/python3.10/site-packages/graphistry/pygraphistry.py:1029, in PyGraphistry.cypher(query, params)
1014 @staticmethod
1015 def cypher(query, params={}):
1016 """
1017
1018 :param query: a cypher query
(...)
1027 g = graphistry.bolt({ query='MATCH (a)-[r:PAYMENT]->(b) WHERE r.USD > 7000 AND r.USD < 10000 RETURN r ORDER BY r.USD DESC', params={ "AccountId": 10 })
1028 """
-> 1029 return Plotter().cypher(query, params)
File ~/anaconda3/envs/JupyterSystemEnv/lib/python3.10/site-packages/graphistry/PlotterBase.py:2053, in PlotterBase.cypher(self, query, params)
2051 bolt_statement = session.run(query, **params)
2052 graph = bolt_statement.graph()
-> 2053 edges = bolt_graph_to_edges_dataframe(graph)
2054 nodes = bolt_graph_to_nodes_dataframe(graph)
2055 return res\
2056 .bind(
2057 node=node_id_key,
(...)
2061 .nodes(nodes)\
2062 .edges(edges)
File ~/anaconda3/envs/JupyterSystemEnv/lib/python3.10/site-packages/graphistry/bolt_util.py:31, in bolt_graph_to_edges_dataframe(graph)
30 def bolt_graph_to_edges_dataframe(graph):
---> 31 df = pd.DataFrame([
32 util.merge_two_dicts(
33 { key: value for (key, value) in relationship.items() },
34 {
35 relationship_id_key: relationship.element_id, # noqa: E241
36 relationship_type_key: relationship.type, # noqa: E241
37 start_node_id_key: relationship.start_node.element_id, # noqa: E241
38 end_node_id_key: relationship.end_node.element_id # noqa: E241
39 }
40 )
41 for relationship in graph.relationships
42 ])
43 if len(df) == 0:
44 util.warn('Query returned no edges; may have surprising visual results or need to add missing columns for encodings')
File ~/anaconda3/envs/JupyterSystemEnv/lib/python3.10/site-packages/graphistry/bolt_util.py:35, in <listcomp>(.0)
30 def bolt_graph_to_edges_dataframe(graph):
31 df = pd.DataFrame([
32 util.merge_two_dicts(
33 { key: value for (key, value) in relationship.items() },
34 {
---> 35 relationship_id_key: relationship.element_id, # noqa: E241
36 relationship_type_key: relationship.type, # noqa: E241
37 start_node_id_key: relationship.start_node.element_id, # noqa: E241
38 end_node_id_key: relationship.end_node.element_id # noqa: E241
39 }
40 )
41 for relationship in graph.relationships
42 ])
43 if len(df) == 0:
44 util.warn('Query returned no edges; may have surprising visual results or need to add missing columns for encodings')
AttributeError: 'member' object has no attribute 'element_id'