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

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

Closed
Yag-ger opened this issue Jan 9, 2024 · 4 comments · Fixed by #254
Closed

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

Yag-ger opened this issue Jan 9, 2024 · 4 comments · Fixed by #254

Comments

@Yag-ger
Copy link

Yag-ger commented Jan 9, 2024

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 detect_anomalies
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
Copy link

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

@Yibei990826
Copy link
Contributor

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
Copy link
Member

jmoralez commented Mar 7, 2024

I think there's a bug here

nixtla/nixtlats/timegpt.py

Lines 193 to 206 in 7ceb253

time_col = df.index.name
if time_col is None:
time_col = "ds"
df.index.name = time_col
df = df.reset_index()
else:
self.freq = self.base_freq
renamer = {
self.id_col: "unique_id",
self.time_col: "ds",
self.target_col: "y",
}
df = df.rename(columns=renamer)
if df.dtypes.ds != "object":

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
Copy link
Contributor

I think there's a bug here

nixtla/nixtlats/timegpt.py

Lines 193 to 206 in 7ceb253

time_col = df.index.name
if time_col is None:
time_col = "ds"
df.index.name = time_col
df = df.reset_index()
else:
self.freq = self.base_freq
renamer = {
self.id_col: "unique_id",
self.time_col: "ds",
self.target_col: "y",
}
df = df.rename(columns=renamer)
if df.dtypes.ds != "object":

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()

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.

4 participants