Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Uninformative TypeError using tsfeatures when series_length < 12 #16

Closed
chillerobscuro opened this issue Dec 2, 2022 · 3 comments · Fixed by #18
Closed

[Bug] Uninformative TypeError using tsfeatures when series_length < 12 #16

chillerobscuro opened this issue Dec 2, 2022 · 3 comments · Fixed by #18

Comments

@chillerobscuro
Copy link

I'm trying to run this on a test series of length 11 and freq='D', and getting TypeError: 'float' object is not subscriptable.

Is this expected/unavoidable? Ideally it could be fixed even if some features must return NaN or similar. Otherwise there could be a more informative error, or just check if the series_length is too small and raise an exception. Here is some code that breaks when the series_length is 11, but works when it's 12.

import numpy as np
import pandas as pd
from tsfeatures import tsfeatures

periods = 11
ind = pd.date_range(start='2000-01-01', periods=periods, freq='D')
vals = np.random.rand(periods)

df = pd.DataFrame({'ds':ind, 'y':vals, 'unique_id':1})
print(f'Inferred freq: {pd.infer_freq(df.ds)}')
print(df.head())

tsfeatures(df)

Output >

Inferred freq: D
          ds         y  unique_id
0 2000-01-01  0.576768          1
1 2000-01-02  0.482616          1
2 2000-01-03  0.848193          1
3 2000-01-04  0.180783          1
4 2000-01-05  0.060860          1

---------------------------------------------------------------------------
RemoteTraceback                           Traceback (most recent call last)
RemoteTraceback: 
"""
Traceback (most recent call last):
  File "/usr/local/Cellar/python@3.9/3.9.4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
  File "/usr/local/Cellar/python@3.9/3.9.4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/pool.py", line 51, in starmapstar
    return list(itertools.starmap(args[0], args[1]))
  File "/Users/loganduffy/Code/ts/notebooks/tsdl/lib/python3.9/site-packages/tsfeatures/tsfeatures.py", line 871, in _get_feats
    c_map = ChainMap(*[dict_feat for dict_feat in [func(ts, freq) for func in features]])
  File "/Users/loganduffy/Code/ts/notebooks/tsdl/lib/python3.9/site-packages/tsfeatures/tsfeatures.py", line 871, in <listcomp>
    c_map = ChainMap(*[dict_feat for dict_feat in [func(ts, freq) for func in features]])
  File "/Users/loganduffy/Code/ts/notebooks/tsdl/lib/python3.9/site-packages/tsfeatures/tsfeatures.py", line 539, in pacf_features
    pacf_5 = np.sum(pacfx[1:6] ** 2)
TypeError: 'float' object is not subscriptable
"""

The above exception was the direct cause of the following exception:

TypeError                                 Traceback (most recent call last)
Input In [239], in <cell line: 13>()
     10 print(f'Inferred freq: {pd.infer_freq(df.ds)}')
     11 print(df.head())
---> 13 tsfeatures(df)

File ~/Code/ts/notebooks/tsdl/lib/python3.9/site-packages/tsfeatures/tsfeatures.py:916, in tsfeatures(ts, freq, features, dict_freqs, scale, threads)
    912 partial_get_feats = partial(_get_feats, freq=freq, scale=scale,
    913                             features=features, dict_freqs=dict_freqs)
    915 with Pool(threads) as pool:
--> 916     ts_features = pool.starmap(partial_get_feats, ts.groupby('unique_id'))
    918 ts_features = pd.concat(ts_features).rename_axis('unique_id')
    919 ts_features = ts_features.reset_index()

File /usr/local/Cellar/python@3.9/3.9.4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/pool.py:372, in Pool.starmap(self, func, iterable, chunksize)
    366 def starmap(self, func, iterable, chunksize=None):
    367     '''
    368     Like `map()` method but the elements of the `iterable` are expected to
    369     be iterables as well and will be unpacked as arguments. Hence
    370     `func` and (a, b) becomes func(a, b).
    371     '''
--> 372     return self._map_async(func, iterable, starmapstar, chunksize).get()

File /usr/local/Cellar/python@3.9/3.9.4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/pool.py:771, in ApplyResult.get(self, timeout)
    769     return self._value
    770 else:
--> 771     raise self._value

TypeError: 'float' object is not subscriptable
@AzulGarza
Copy link
Member

Hey @chillerobscuro! Thank you for reporting this.

I was able to reproduce the error. Let me dig into it.

@chillerobscuro
Copy link
Author

Hey @FedericoGarza I know these things take time but any luck finding the root issue? If it's a straightforward fix I could open a PR

AzulGarza added a commit that referenced this issue Dec 8, 2022
@AzulGarza AzulGarza mentioned this issue Dec 8, 2022
AzulGarza added a commit that referenced this issue Dec 8, 2022
@AzulGarza
Copy link
Member

hey @chillerobscuro! We release a new version (0.4.0) that fixes the issue 🙌

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants