Skip to content

Commit 0dd74fd

Browse files
committed
Make sure to return the correct columns for stream[Node/Relationship]Properties
1 parent 030b271 commit 0dd74fd

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

graphdatascience/graph/graph_proc_runner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def streamNodeProperties(
113113

114114
# new format was requested, but the query was run via Cypher
115115
if separate_property_columns and "propertyValue" in result.keys():
116-
return result.pivot_table("propertyValue", "nodeId", columns="nodeProperty")
116+
return result.pivot_table("propertyValue", "nodeId", columns="nodeProperty").reset_index()
117117
# old format was requested but the query was run via Arrow
118118
elif not separate_property_columns and "propertyValue" not in result.keys():
119119
return result.melt(id_vars=["nodeId"]).rename(
@@ -149,7 +149,7 @@ def streamRelationshipProperties(
149149
if separate_property_columns and "propertyValue" in result.keys():
150150
return result.pivot_table(
151151
"propertyValue", ["sourceNodeId", "targetNodeId", "relationshipType"], columns="relationshipProperty"
152-
)
152+
).reset_index()
153153
# old format was requested but the query was run via Arrow
154154
elif not separate_property_columns and "propertyValue" not in result.keys():
155155
return result.melt(id_vars=["sourceNodeId", "targetNodeId", "relationshipType"]).rename(

graphdatascience/tests/integration/test_graph_ops.py

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,17 +168,20 @@ def test_graph_streamNodeProperties(gds: GraphDataScience) -> None:
168168

169169
result = gds.graph.streamNodeProperties(G, ["x", "y"], concurrency=2)
170170

171+
assert list(result.keys()) == ["nodeId", "nodeProperty", "propertyValue"]
172+
171173
x_values = result[result.nodeProperty == "x"]
172174
assert {e for e in x_values["propertyValue"]} == {1, 2, 3}
173175

174176
y_values = result[result.nodeProperty == "y"]
175177
assert {e for e in y_values["propertyValue"]} == {2, 3, 4}
176178

177179

178-
def test_graph_streamNodeProperties_merge_property_columns(gds: GraphDataScience) -> None:
180+
def test_graph_streamNodeProperties_separate_property_columns(gds: GraphDataScience) -> None:
179181
G, _ = gds.graph.project(GRAPH_NAME, {"Node": {"properties": ["x", "y"]}}, "*")
180182

181183
result = gds.graph.streamNodeProperties(G, ["x", "y"], separate_property_columns=True, concurrency=2)
184+
assert list(result.keys()) == ["nodeId", "x", "y"]
182185
assert {e for e in result["x"]} == {1, 2, 3}
183186
assert {e for e in result["y"]} == {2, 3, 4}
184187

@@ -187,17 +190,24 @@ def test_graph_streamNodeProperties_without_arrow(gds_without_arrow: GraphDataSc
187190
G, _ = gds_without_arrow.graph.project(GRAPH_NAME, {"Node": {"properties": ["x", "y"]}}, "*")
188191

189192
result = gds_without_arrow.graph.streamNodeProperties(G, ["x", "y"], concurrency=2)
193+
194+
assert list(result.keys()) == ["nodeId", "nodeProperty", "propertyValue"]
195+
190196
x_values = result[result.nodeProperty == "x"]
191197
assert {e for e in x_values["propertyValue"]} == {1, 2, 3}
192198

193199
y_values = result[result.nodeProperty == "y"]
194200
assert {e for e in y_values["propertyValue"]} == {2, 3, 4}
195201

196202

197-
def test_graph_streamNodeProperties_without_arrow_merge_property_columns(gds_without_arrow: GraphDataScience) -> None:
203+
def test_graph_streamNodeProperties_without_arrow_separate_property_columns(
204+
gds_without_arrow: GraphDataScience,
205+
) -> None:
198206
G, _ = gds_without_arrow.graph.project(GRAPH_NAME, {"Node": {"properties": ["x", "y"]}}, "*")
199207

200208
result = gds_without_arrow.graph.streamNodeProperties(G, ["x", "y"], separate_property_columns=True, concurrency=2)
209+
210+
assert list(result.keys()) == ["nodeId", "x", "y"]
201211
assert {e for e in result["x"]} == {1, 2, 3}
202212
assert {e for e in result["y"]} == {2, 3, 4}
203213

@@ -221,17 +231,26 @@ def test_graph_streamRelationshipProperties(gds: GraphDataScience) -> None:
221231

222232
result = gds.graph.streamRelationshipProperties(G, ["relX", "relY"], concurrency=2)
223233

234+
assert list(result.keys()) == [
235+
"sourceNodeId",
236+
"targetNodeId",
237+
"relationshipType",
238+
"relationshipProperty",
239+
"propertyValue",
240+
]
241+
224242
x_values = result[result.relationshipProperty == "relX"]
225243
assert {e for e in x_values["propertyValue"]} == {4, 5, 6}
226244
y_values = result[result.relationshipProperty == "relY"]
227245
assert {e for e in y_values["propertyValue"]} == {5, 6, 7}
228246

229247

230-
def test_graph_streamRelationshipProperties_merge_property_columns(gds: GraphDataScience) -> None:
248+
def test_graph_streamRelationshipProperties_separate_property_columns(gds: GraphDataScience) -> None:
231249
G, _ = gds.graph.project(GRAPH_NAME, "*", {"REL": {"properties": ["relX", "relY"]}})
232250

233251
result = gds.graph.streamRelationshipProperties(G, ["relX", "relY"], separate_property_columns=True, concurrency=2)
234-
assert {e for e in result["relationshipType"]} == {"REL", "REL", "REL"}
252+
253+
assert list(result.keys()) == ["sourceNodeId", "targetNodeId", "relationshipType", "relX", "relY"]
235254
assert {e for e in result["relX"]} == {4, 5, 6}
236255
assert {e for e in result["relY"]} == {5, 6, 7}
237256

@@ -241,20 +260,30 @@ def test_graph_streamRelationshipProperties_without_arrow(gds_without_arrow: Gra
241260

242261
result = gds_without_arrow.graph.streamRelationshipProperties(G, ["relX", "relY"], concurrency=2)
243262

263+
assert list(result.keys()) == [
264+
"sourceNodeId",
265+
"targetNodeId",
266+
"relationshipType",
267+
"relationshipProperty",
268+
"propertyValue",
269+
]
270+
244271
x_values = result[result.relationshipProperty == "relX"]
245272
assert {e for e in x_values["propertyValue"]} == {4, 5, 6}
246273
y_values = result[result.relationshipProperty == "relY"]
247274
assert {e for e in y_values["propertyValue"]} == {5, 6, 7}
248275

249276

250-
def test_graph_streamRelationshipProperties_without_arrow_merge_property_columns(
277+
def test_graph_streamRelationshipProperties_without_arrow_separate_property_columns(
251278
gds_without_arrow: GraphDataScience,
252279
) -> None:
253280
G, _ = gds_without_arrow.graph.project(GRAPH_NAME, "*", {"REL": {"properties": ["relX", "relY"]}})
254281

255282
result = gds_without_arrow.graph.streamRelationshipProperties(
256283
G, ["relX", "relY"], separate_property_columns=True, concurrency=2
257284
)
285+
286+
assert list(result.keys()) == ["sourceNodeId", "targetNodeId", "relationshipType", "relX", "relY"]
258287
assert {e for e in result["relX"]} == {4, 5, 6}
259288
assert {e for e in result["relY"]} == {5, 6, 7}
260289

0 commit comments

Comments
 (0)