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

01_getting_started_complete #1239

Closed
kgboyko opened this issue Jan 2, 2025 · 1 comment
Closed

01_getting_started_complete #1239

kgboyko opened this issue Jan 2, 2025 · 1 comment

Comments

@kgboyko
Copy link

kgboyko commented Jan 2, 2025

Description

Description

Block:
cv_df.columns = cv_df.columns.str.replace('-median', '')
cv_df.head()

for cutoff in cv_df['cutoff'].unique():
StatsForecast.plot(
Y_df,
cv_df.query('cutoff == @cutoff').drop(columns=['y', 'cutoff']),
max_insample_length=48 * 4,
unique_ids=['H185'],
engine='matplotlib'
)

Need add line:
cv_df = cv_df.reset_index()
after line:
cv_df.columns = cv_df.columns.str.replace('-median', '')


KeyError Traceback (most recent call last)
File /opt/conda/lib/python3.10/site-packages/pandas/core/indexes/base.py:3805, in Index.get_loc(self, key)
3804 try:
-> 3805 return self._engine.get_loc(casted_key)
3806 except KeyError as err:

File index.pyx:167, in pandas._libs.index.IndexEngine.get_loc()

File index.pyx:196, in pandas._libs.index.IndexEngine.get_loc()

File pandas/_libs/hashtable_class_helper.pxi:7081, in pandas._libs.hashtable.PyObjectHashTable.get_item()

File pandas/_libs/hashtable_class_helper.pxi:7089, in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 'unique_id'

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

KeyError Traceback (most recent call last)
Cell In[52], line 2
1 for cutoff in cv_df['cutoff'].unique():
----> 2 StatsForecast.plot(
3 Y_df,
4 cv_df.query('cutoff == @cutoff').drop(columns=['y', 'cutoff']),
5 max_insample_length=48 * 4,
6 unique_ids=['H185'],
7 engine='matplotlib'
8 )

File /opt/conda/lib/python3.10/site-packages/statsforecast/core.py:1306, in _StatsForecast.plot(df, forecasts_df, unique_ids, plot_random, models, level, max_insample_length, plot_anomalies, engine, id_col, time_col, target_col, resampler_kwargs)
1304 if forecasts_df is not None:
1305 forecasts_df = ensure_time_dtype(forecasts_df, time_col)
-> 1306 return plot_series(
1307 df=df,
1308 forecasts_df=forecasts_df,
1309 ids=unique_ids,
1310 plot_random=plot_random,
1311 models=models,
1312 level=level,
1313 max_insample_length=max_insample_length,
1314 plot_anomalies=plot_anomalies,
1315 engine=engine,
1316 resampler_kwargs=resampler_kwargs,
1317 palette="tab20b",
1318 id_col=id_col,
1319 time_col=time_col,
1320 target_col=target_col,
1321 )

File /opt/conda/lib/python3.10/site-packages/utilsforecast/plotting.py:212, in plot_series(df, forecasts_df, ids, plot_random, max_ids, models, level, max_insample_length, plot_anomalies, engine, palette, id_col, time_col, target_col, seed, resampler_kwargs, ax)
203 df = _filter_series(
204 df=df,
205 id_col=id_col,
(...)
209 max_insample_length=max_insample_length,
210 )
211 if forecasts_df is not None:
--> 212 forecasts_df = _filter_series(
213 df=forecasts_df,
214 id_col=id_col,
215 time_col=time_col,
216 uids=uids,
217 models=[target_col] + models if target_col in forecasts_df else models,
218 max_insample_length=None,
219 )
220 if df is None:
221 df = forecasts_df

File /opt/conda/lib/python3.10/site-packages/utilsforecast/plotting.py:39, in _filter_series(df, id_col, time_col, uids, models, max_insample_length)
35 interval_cols = [
36 c for c in df.columns if re.search(rf"^({models_pat})-(?:lo|hi)-\d+", c)
37 ]
38 out_cols.extend(models + interval_cols)
---> 39 mask = ufp.is_in(df[id_col], uids)
40 df = ufp.filter_with_mask(df, mask)
41 df = df[out_cols]

File /opt/conda/lib/python3.10/site-packages/pandas/core/frame.py:4102, in DataFrame.getitem(self, key)
4100 if self.columns.nlevels > 1:
4101 return self._getitem_multilevel(key)
-> 4102 indexer = self.columns.get_loc(key)
4103 if is_integer(indexer):
4104 indexer = [indexer]

File /opt/conda/lib/python3.10/site-packages/pandas/core/indexes/base.py:3812, in Index.get_loc(self, key)
3807 if isinstance(casted_key, slice) or (
3808 isinstance(casted_key, abc.Iterable)
3809 and any(isinstance(x, slice) for x in casted_key)
3810 ):
3811 raise InvalidIndexError(key)
-> 3812 raise KeyError(key) from err
3813 except TypeError:
3814 # If we have a listlike key, _check_indexing_error will raise
3815 # InvalidIndexError. Otherwise we fall through and re-raise
3816 # the TypeError.
3817 self._check_indexing_error(key)

KeyError: 'unique_id'

Link

No response

Link

No response

@kgboyko kgboyko closed this as completed Jan 2, 2025
@kgboyko kgboyko reopened this Jan 2, 2025
@jmoralez
Copy link
Member

jmoralez commented Jan 2, 2025

Fixed by 2.0 release

@jmoralez jmoralez closed this as completed Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants