2

I am trying to run the detect_ts function from pyculiarity package but getting this error on passing a two-dimensional dataframe in python.

>>> import pandas as pd
>>> from pyculiarity import detect_ts
>>> data=pd.read_csv('C:\\Users\\nikhil.chauhan\\Desktop\\Bosch_Frame\\dataset1.csv',usecols=['time','value'])
>>> data.head()
   time  value
0     0   32.0
1   250   40.5
2   500   40.5
3   750   34.5
4  1000   34.5
>>> results = detect_ts(data,max_anoms=0.05,alpha=0.001,direction = 'both')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Windows\System32\pyculiar-0.0.5\pyculiarity\detect_ts.py", line 177, in detect_ts
    verbose=verbose)
  File "C:\Windows\System32\pyculiar-0.0.5\pyculiarity\detect_anoms.py", line 69, in detect_anoms
    decomp = stl(data.value, np=num_obs_per_period)
  File "C:\Windows\System32\pyculiar-0.0.5\pyculiarity\stl.py", line 35, in stl
    res = sm.tsa.seasonal_decompose(data.values, model='additive', freq=np)
  File "C:\Anaconda3\lib\site-packages\statsmodels\tsa\seasonal.py", line 88, in seasonal_decompose
    trend = convolution_filter(x, filt)
  File "C:\Anaconda3\lib\site-packages\statsmodels\tsa\filters\filtertools.py", line 303, in convolution_filter
    result = _pad_nans(result, trim_head, trim_tail)
  File "C:\Anaconda3\lib\site-packages\statsmodels\tsa\filters\filtertools.py", line 28, in _pad_nans
    return np.r_[[np.nan] * head, x, [np.nan] * tail]
TypeError: 'numpy.float64' object cannot be interpreted as an integer
2
  • I'd review the docs for detect_ts. Make sure the inputs are the right type(s). data.values extracts an array from data. The other approach is to work from the end, deducing what head, x, and tail are. [np.nan]*np.float64(2) produces your error. Commented Feb 17, 2017 at 6:31
  • The same error occured to me... When I enabled the folder path for accessing the data. (For eg: G folder/Shared link) The error got rectified because link to access data was activated. Commented May 10, 2017 at 7:47

1 Answer 1

1

The problem with your code might be that np.nan is a float64 type value but the np.r_[] expects comma separated integers within its square brackets. Hence you need to convert them to integer type first.

But we have another problem here.

return np.r_[[(int)(np.nan)] * head, x, [(int)(np.nan)] * tail]

This should have solved the problem in ordinary cases.... But it wont work in this case, as NaN cannot be type casted to integer type.

ValueError: cannot convert float NaN to integer

Thus, no proper solution can be suggested unless we know what you are trying to do here. Try providing a bit more details about your code and you are sure to get help from us.

:-)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.