caesar0301 / treelib

An efficient implementation of tree data structure in python 2/3.
http://treelib.readthedocs.io/en/latest/
Other
800 stars 185 forks source link

potential bug for data parameter in Node #206

Open cli0 opened 1 year ago

cli0 commented 1 year ago

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.