Skip to content

Commit

Permalink
improve error msgs (#715)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmoralez authored Dec 4, 2023
1 parent 50fc8d3 commit 1fc40f9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
23 changes: 7 additions & 16 deletions nbs/src/core/core.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -838,9 +838,9 @@
"#| exporti\n",
"def _warn_df_constructor():\n",
" warnings.warn(\n",
" \"The `df` argument of the StatsForecast constructor is deprecated \"\n",
" \"and will be removed in a future version. \"\n",
" \"Please pass `df` to the fit/forecast methods instead.\",\n",
" \"The `df` argument of the StatsForecast constructor as well as reusing stored \"\n",
" \"dfs from other methods is deprecated and will raise an error in a future version. \"\n",
" \"Please provide the `df` argument to the corresponding method instead, e.g. fit/forecast.\",\n",
" category=DeprecationWarning,\n",
" )\n",
"\n",
Expand Down Expand Up @@ -920,8 +920,7 @@
" self.freq = freq\n",
" self.n_jobs = n_jobs\n",
" self.fallback_model = fallback_model\n",
" self.verbose = verbose \n",
" self.n_jobs == 1\n",
" self.verbose = verbose\n",
" if df is not None:\n",
" _warn_df_constructor()\n",
" self._prepare_fit(df=df, sort_df=sort_df)\n",
Expand All @@ -941,6 +940,8 @@
" sort_df: bool = True,\n",
" ) -> None:\n",
" if df is None:\n",
" if not hasattr(self, 'ga'):\n",
" raise ValueError('You must provide the `df` argument.')\n",
" _warn_df_constructor()\n",
" return\n",
" df = ensure_time_dtype(df, 'ds')\n",
Expand Down Expand Up @@ -1920,24 +1921,14 @@
"assert all('the predictions will have the id as a column' in str(w.message) for w in issued_warnings)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "50d26dc0-5cfa-4328-a7ba-227940204b40",
"metadata": {},
"outputs": [],
"source": [
"import statsforecast"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "229e3746-68d2-4038-8926-240ab1e08b9f",
"metadata": {},
"outputs": [],
"source": [
"statsforecast.config.id_as_index = False"
"sf_config.id_as_index = False"
]
},
{
Expand Down
9 changes: 5 additions & 4 deletions statsforecast/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,9 @@ def _get_n_jobs(n_groups, n_jobs):
# %% ../nbs/src/core/core.ipynb 27
def _warn_df_constructor():
warnings.warn(
"The `df` argument of the StatsForecast constructor is deprecated "
"and will be removed in a future version. "
"Please pass `df` to the fit/forecast methods instead.",
"The `df` argument of the StatsForecast constructor as well as reusing stored "
"dfs from other methods is deprecated and will raise an error in a future version. "
"Please provide the `df` argument to the corresponding method instead, e.g. fit/forecast.",
category=DeprecationWarning,
)

Expand Down Expand Up @@ -490,7 +490,6 @@ def __init__(
self.n_jobs = n_jobs
self.fallback_model = fallback_model
self.verbose = verbose
self.n_jobs == 1
if df is not None:
_warn_df_constructor()
self._prepare_fit(df=df, sort_df=sort_df)
Expand All @@ -512,6 +511,8 @@ def _prepare_fit(
sort_df: bool = True,
) -> None:
if df is None:
if not hasattr(self, "ga"):
raise ValueError("You must provide the `df` argument.")
_warn_df_constructor()
return
df = ensure_time_dtype(df, "ds")
Expand Down

0 comments on commit 1fc40f9

Please sign in to comment.