vc1492a / PyNomaly

Anomaly detection using LoOP: Local Outlier Probabilities, a local density based outlier detection method providing an outlier score in the range of [0,1].
Other
305 stars 36 forks source link

Progress bar fails with ZeroDivisionError using a small number of observations #35

Closed vc1492a closed 4 years ago

vc1492a commented 4 years ago

The below line contained within PyNomaly/loop.py fails with a ZeroDivisionError when the total number of observations is less than the terminal or cell width where the code was executed.

https://github.com/vc1492a/PyNomaly/blob/744fa57fde27f369f6265ffe57ecb3db3d3374ea/PyNomaly/loop.py#L36

The cause is a block_size of 0, which is not allowable with the current implementation.

This can be resolved by changing the code to the following:

    if total < w:
        block_size = int(w / total)
    else:
        block_size = int(total / w)

if index % block_size == 0:

Which will ensure the block_size remains greater than 0 even when the number of observations is less than the width of the terminal / cell window.

vc1492a commented 4 years ago

A unit test has been written in a separate library to ensure that the progress bar is exhibiting the proper behavior when utilized, and can be included as part of the patch for this issue.

vc1492a commented 4 years ago

Added as part of version 0.3.3.