Nixtla / nixtla

TimeGPT-1: production ready pre-trained Time Series Foundation Model for forecasting and anomaly detection. Generative pretrained transformer for time series trained on over 100B data points. It's capable of accurately predicting various domains such as retail, electricity, finance, and IoT with just a few lines of code 🚀.
https://docs.nixtla.io
Other
1.91k stars 151 forks source link

'Series' object has no attribute 'ds'. Did you mean: 'xs' #208

Closed Yag-ger closed 3 months ago

Yag-ger commented 5 months ago

Student & first GitHub Post ever. I hope this is the right issue in the right place. Feel free to move this post.

I am using Nixtlats TimeGPT in Python and I already created a token on the website. The token also works, the validation function gives back true. Upon calling the function detect_anomalies on a simple timeseries the following error is shown:

AttributeError: 'Series' object has no attribute 'ds'. Did you mean: 'xs'?

I tried to find a solution in the docs but couldnt find any. I also tried to rename my date column to ds. Still no Luck.

Logs:

outliers_timegpt = timegpt.detect_anomalies(timeseries, time_col='ds', target_col='prognosebasis', freq='W') ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ygerkman\AppData\Local\miniconda3\Lib\site-packages\nixtlats\timegpt.py", line 1190, in detect_anomalies return self._detect_anomalies( ^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ygerkman\AppData\Local\miniconda3\Lib\site-packages\nixtlats\timegpt.py", line 625, in wrapper return func(self, *args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ygerkman\AppData\Local\miniconda3\Lib\site-packages\nixtlats\timegpt.py", line 643, in wrapper return func(self, kwargs, num_partitions=1) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ygerkman\AppData\Local\miniconda3\Lib\site-packages\nixtlats\timegpt.py", line 818, in _detect_anomalies anomalies_df = timegpt_model.detect_anomalies(df=df) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ygerkman\AppData\Local\miniconda3\Lib\site-packages\nixtlats\timegpt.py", line 527, in detectanomalies df, = self.transform_inputs(df=df, X_df=None) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ygerkman\AppData\Local\miniconda3\Lib\site-packages\nixtlats\timegpt.py", line 188, in transform_inputs if df.dtypes.ds != "object": ^^^^^^^^^^^^ File "C:\Users\ygerkman\AppData\Local\miniconda3\Lib\site-packages\pandas\core\generic.py", line 5902, in getattr return object.getattribute(self, name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'Series' object has no attribute 'ds'. Did you mean: 'xs'?

grace001214 commented 4 months ago

你好,我也遇到了这个问题,想问下您解决这个问题了么,如何解决的呢

Yibei990826 commented 4 months ago

Hi @Yag-ger and @grace001214. I was not able to replicate this problem, but I think it might be a column naming issue. Could you please rename the timestamp column and let me know if the problem is still persistent?

jmoralez commented 4 months ago

I think there's a bug here https://github.com/Nixtla/nixtla/blob/7ceb2532c0911086dd27285ef281a9d10d63cfd3/nixtlats/timegpt.py#L193-L206

If the name of the index is 'hello' and the TimeGPT object is initialized like TimeGPT(time_col='ds') (the default) it'll try to rename 'ds': 'ds' which won't do anything since that column won't exist, it should instead rename 'hello': 'ds'

Yibei990826 commented 4 months ago

I think there's a bug here

https://github.com/Nixtla/nixtla/blob/7ceb2532c0911086dd27285ef281a9d10d63cfd3/nixtlats/timegpt.py#L193-L206

If the name of the index is 'hello' and the TimeGPT object is initialized like TimeGPT(time_col='ds') (the default) it'll try to rename 'ds': 'ds' which won't do anything since that column won't exist, it should instead rename 'hello': 'ds'

I agree with you, we will see this issue anytime the date col is passed as index, (even though it might be named 'ds'). For instance, I was able to replicate the issue with the following data:

image

I think it might be helpful to add something like:

elif hasattr(df.index, "freq") and  hasattr(df.index, "name"):
     if df.index.name = self.time_col:
        df=df.reset_index()