kLabUM / rrcf

🌲 Implementation of the Robust Random Cut Forest algorithm for anomaly detection on streams
https://klabum.github.io/rrcf/
MIT License
495 stars 112 forks source link

to_dict() on an empty tree fails #82

Open TrigonaMinima opened 3 years ago

TrigonaMinima commented 3 years ago

While saving an empty tree TypeError is raised. Here's the code:

import rrcf
a = rrcf.RCTree()
a.to_dict()

and the stack trace:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/anaconda3/lib/python3.7/site-packages/rrcf/rrcf.py", line 748, in to_dict
    self._serialize(self.root, obj, duplicates)
  File "/anaconda3/lib/python3.7/site-packages/rrcf/rrcf.py", line 780, in _serialize
    raise TypeError('`node` must be Branch or Leaf instance')
TypeError: `node` must be Branch or Leaf instance