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

Problem exporting to JSON and dict #205

Open LuisGGon opened 1 year ago

LuisGGon commented 1 year ago

Hello.

I have built a CHAID decision tree and I got a tree object with the code tree_obj = tree.to_tree(). Afterwards, I have tried to save the tree into a dict file with the command tree_obj.to_dict(), but I got the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/LuisG/anaconda3/lib/python3.8/site-packages/treelib/tree.py", line 964, in to_dict
    tree_dict = {ntag: {"children": []}}
  File "/home/LuisG/anaconda3/lib/python3.8/site-packages/CHAID/node.py", line 42, in __hash__
    return hash(self.__dict__)
TypeError: unhashable type: 'dict'

Something similar happens when I tried to save the tree as a JSON file.