Skip to content

Commit 80e199c

Browse files
committed
Handle empty table in arrow based stream
1 parent 02657fb commit 80e199c

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* Fixed an issue where configuration parameters such as `aggregation` were ignored by `gds.graph.toUndirected`.
2222
* Fixed an issue where the `database` given for the `GraphDataScience` construction was not used for metadata retrieval, causing an exception to be raised if the default "neo4j" database was missing.
2323
* Fixed an issue where progress bars would not always complete.
24+
* Fixed an issue where an empty relationship type could not be streamed.
2425

2526

2627
## Improvements

graphdatascience/query_runner/arrow_query_runner.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,10 @@ def create_graph_constructor(
325325
)
326326

327327
def _sanitize_arrow_table(self, arrow_table: Table) -> Table:
328+
# empty columns cannot be used to build a chunked_array in pyarrow
329+
if len(arrow_table) == 0:
330+
return arrow_table
331+
328332
dict_encoded_fields = [
329333
(idx, field) for idx, field in enumerate(arrow_table.schema) if is_dictionary(field.type)
330334
]

graphdatascience/tests/integration/test_graph_ops.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import numpy as np
55
import pytest
6-
from pandas import Series
6+
from pandas import DataFrame, Series
77

88
from graphdatascience.graph_data_science import GraphDataScience
99
from graphdatascience.query_runner.arrow_query_runner import ArrowQueryRunner
@@ -999,3 +999,16 @@ def test_graph_nodeProperty_stream_via_run_query(gds: GraphDataScience) -> None:
999999
)
10001000
)
10011001
assert {e for e in result["degree"]} == {1, 2, 3}
1002+
1003+
1004+
def test_empty_relationships_stream(gds: GraphDataScience) -> None:
1005+
G = gds.graph.construct(GRAPH_NAME, nodes=DataFrame({"nodeId": [0, 1]}))
1006+
gds.nodeSimilarity.filtered.mutate(
1007+
G, mutateRelationshipType="SIMILAR", mutateProperty="score", similarityCutoff=0.99
1008+
)
1009+
1010+
assert G.relationship_count() == 0
1011+
assert G.relationship_types()
1012+
1013+
result = gds.graph.relationships.stream(G, ["SIMILAR"])
1014+
assert result.empty

0 commit comments

Comments
 (0)