caesar0301/treelib

potential bug for data parameter in Node

cli0 opened this issue · 0 comments

cli0 commented

I am trying to filter nodes based on custom parameters that I uploaded in the data field. Namely I create a class and assign to dataa particular class.

However when I try to go through the nodes via filter, the node.data is not recognized and gives me a Nonetype. The following is my code and errors:

def tree():
    tree = Tree()
    tree.create_node("Harry", "harry")  # root node
    tree.create_node("Jane", "jane", parent="harry", data=Objects({"nae":1,"surname":2},5))
    tree.create_node("Bill", "bill", parent="harry", data=Objects({"nae":1,"surname":2},88))
    tree.create_node("Diane", "diane", parent="jane", data=Objects({"nae":1,"surname":2},2))
    tree.create_node("Mary", "mary", parent="diane", data=Objects({"nae":1,"surname":2},1))
    tree.create_node("Mark", "mark", parent="jane", data= Objects({"nae":1,"surname":2},20))

    x = tree.filter_nodes(lambda y: y.data.b >7)
    for i in x:
        print(i)

AttributeError: 'NoneType' object has no attribute 'b'

Alternatively if I try to filter the tree based on the identifier or tag it all works out fine. Just data is not recognized at all and throws a Nonetype immediately as it is called.

Am I doing something wrong here or is filtering based on data not supported by the library?

Thanks in advance.