neo4j / graph-data-science

Source code for the Neo4j Graph Data Science library of graph algorithms.
https://neo4j.com/docs/graph-data-science/current/
Other
596 stars 157 forks source link

Using "<" and "<=" or floats in filtering does not work in gds.alpha.graph.nodeLabel.write/mutate #253

Closed mlnrt closed 11 months ago

mlnrt commented 1 year ago

Describe the bugs BUG 1: Using "<" or "<=" signs to filter nodes when trying to mutate node labels does not work, while it works with ">" and ">=" signs. This writes 0 node labels CALL gds.alpha.graph.nodeLabel.write("all_members", 'ClimbedDuringExploratoryPeriod', {nodeFilter:'n.firstExpeditionYear <= 1949'}) While this writes 188 node labels: CALL gds.alpha.graph.nodeLabel.write("all_members", 'ClimbedDuringExploratoryPeriod', {nodeFilter:'1949 >= n.firstExpeditionYear'})

error

BUG 2: Also using floats do not seem to work in filters. These 3 commands writes 0 node labels: CALL gds.alpha.graph.nodeLabel.write("all_members", 'LowDegree', {nodeFilter:'n.degree < 2.0'}) CALL gds.alpha.graph.nodeLabel.write("all_members", 'LowDegree', {nodeFilter:'n.degree < 2'}) CALL gds.alpha.graph.nodeLabel.write("all_members", 'LowDegree', {nodeFilter:'2.0 > n.degree'}) While the below writes a node label on every node even the ones with a degree >= 2.0 CALL gds.alpha.graph.nodeLabel.write("all_members", 'LowDegree', {nodeFilter:'2 > n.degree'})

To Reproduce Use any graph projection with nodes having integer and float properties

Operating system: (for example Windows 10) Neo4j Desktop: 1.5.7 Neo4j: 5.4.0 GDS: 2.3.1

Expected behavior Nodes should be filtered correctly for both float and integer and whatever the comparison operator used

vnickolov commented 1 year ago

@mlnrt thank you for reporting this, we are going to look into the issue and will keep you updated on the progress.

vnickolov commented 1 year ago

@mlnrt I have a couple of questions

When you say

Nodes should be filtered correctly for both float and integer

do you mean mixed properties, for example the value for one node is a float and for another integer?

For BUG 2 is degree a property present on the nodes? The filter works only with existing.

mlnrt commented 1 year ago

@vnickolov sorry, I missed your message. Yes degree is a property I mutate on the nodes. Maybe I was doing something else wrong because for BUG 2 now it works if I do {nodeFilter:'n.degree < 2.0'}

What I mean by

Nodes should be filtered correctly for both float and integer

Is that even if the degree property is a float, I should be able to do both CALL gds.alpha.graph.nodeLabel.write("all_members", 'LowDegree', {nodeFilter:'n.degree < 2.0'}) CALL gds.alpha.graph.nodeLabel.write("all_members", 'LowDegree', {nodeFilter:'n.degree < 2'}) But the second does not work

mlnrt commented 1 year ago

By the way for the first bug I found that CALL gds.alpha.graph.nodeLabel.write("all_members", 'ClimbedDuringExploratoryPeriod', {nodeFilter:'(n.firstExpeditionYear > 1949 AND 1969 >= n.firstExpeditionYear) OR (n.lastExpeditionYear > 1949 AND 1969 >= n.lastExpeditionYear)'}) and CALL gds.alpha.graph.nodeLabel.write("all_members", 'ClimbedDuringExploratoryPeriod', {nodeFilter:'(1949 < n.firstExpeditionYear AND 1969 >= n.firstExpeditionYear) OR (1949 < n.lastExpeditionYear AND 1969 >= n.lastExpeditionYear)'}) give different results, while it should be the same (the only difference is n.firstExpeditionYear > 1949 vs 1949 < n.firstExpeditionYear

image

vnickolov commented 11 months ago

@mlnrt sorry for the late response, we have improved the handling of the filters, will close this issue, please feel free to open a new one if you have any trouble with that. Note that the latest GDS version is now 2.4.3.