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

Wrong use of assert statements #89

Open sebtrack opened 3 years ago

sebtrack commented 3 years ago

I noticed that there are assert statements that are catched wrongly, if an assert statement fails it throws an AssertionError not ValueError nor KeyError.

https://github.com/kLabUM/rrcf/blob/34504c14bba233f86a7dcae35d55fc84cc5b7508/rrcf/rrcf.py#L429-L438

Also consider removing all assert statements, because they are ignored if __debug__ is not True. This is the case when you run in production (See Docs).

The lines could be rewritten as:

        if not point.size == self.ndim:
            raise ValueError(
                "Point must be same dimension as existing points in tree.")
        # Check for existing index in leaves dict
        try:
            self.leaves[index]
        except KeyError:
            raise KeyError("Index already exists in leaves dict.")