Skip to content

Commit

Permalink
Handle input data consisting of constant data specially.
Browse files Browse the repository at this point in the history
This fixes the following warning while running tests:

  RuntimeWarning: invalid value encountered in sign

The cause of this was a division by zero that produces lots of NaNs.
This special case is worth handling explicitly.

Signed-off-by: Uli Schlachter <psychon@znc.in>
  • Loading branch information
psychon committed Apr 19, 2019
1 parent 6808143 commit 5b89c38
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cydets/algorithm.py
Expand Up @@ -69,7 +69,11 @@ def detect_cycles(series, drop_zero_amplitudes=True):

# norm input data
series['norm'] = series['values'] - series['values'].min()
series['norm'] /= series['norm'].max()
maximum = series['norm'].max()
if maximum == 0:
msg = 'Detected constant time series.'
raise ValueError(msg)
series['norm'] /= maximum

# find minima and maxima
min_idx, max_idx = find_peaks_valleys_idx(series['norm'])
Expand Down

0 comments on commit 5b89c38

Please sign in to comment.