Skip to content

Commit

Permalink
rename fn to _id_as_idx
Browse files Browse the repository at this point in the history
  • Loading branch information
jmoralez committed Dec 8, 2023
1 parent 63dfe60 commit fac2701
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 25 deletions.
12 changes: 6 additions & 6 deletions nbs/src/core/core.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -879,8 +879,8 @@
" category=DeprecationWarning,\n",
" )\n",
"\n",
"def _id_as_col() -> bool:\n",
" return bool(os.getenv('NIXTLA_ID_AS_COL', ''))"
"def _id_as_idx() -> bool:\n",
" return not bool(os.getenv('NIXTLA_ID_AS_COL', ''))"
]
},
{
Expand Down Expand Up @@ -1095,7 +1095,7 @@
" uids = ufp.repeat(self.uids, n=h)\n",
" df = self.df_constructor({self.id_col: uids, self.time_col: dates})\n",
" if isinstance(df, pd.DataFrame):\n",
" if not _id_as_col():\n",
" if _id_as_idx():\n",
" _warn_id_as_idx()\n",
" df = df.set_index(self.id_col)\n",
" else:\n",
Expand Down Expand Up @@ -1300,7 +1300,7 @@
" })\n",
" df[cols] = self.fcst_fitted_values_['values']\n",
" if isinstance(df, pd.DataFrame):\n",
" if not _id_as_col():\n",
" if _id_as_idx():\n",
" _warn_id_as_idx()\n",
" df = df.set_index(self.id_col)\n",
" else:\n",
Expand Down Expand Up @@ -1416,7 +1416,7 @@
" # the cv_times is sorted by window and then id\n",
" fcsts_df = ufp.sort(fcsts_df, [id_col, \"cutoff\", time_col])\n",
" fcsts_df = ufp.assign_columns(fcsts_df, res_fcsts[\"cols\"], res_fcsts[\"forecasts\"])\n",
" if isinstance(fcsts_df, pd.DataFrame) and not _id_as_col():\n",
" if isinstance(fcsts_df, pd.DataFrame) and _id_as_idx():\n",
" _warn_id_as_idx()\n",
" fcsts_df = fcsts_df.set_index(id_col)\n",
" return fcsts_df\n",
Expand Down Expand Up @@ -1460,7 +1460,7 @@
" df = ufp.assign_columns(df, self.cv_fitted_values_['cols'], fitted_vals[idxs])\n",
" df = ufp.drop_index_if_pandas(df)\n",
" if isinstance(df, pd.DataFrame):\n",
" if not _id_as_col():\n",
" if _id_as_idx():\n",
" _warn_id_as_idx()\n",
" df = df.set_index(self.id_col)\n",
" else:\n",
Expand Down
8 changes: 4 additions & 4 deletions nbs/src/core/distributed.fugue.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"from fugue.constants import FUGUE_CONF_WORKFLOW_EXCEPTION_INJECT\n",
"from triad import Schema\n",
"\n",
"from statsforecast.core import _StatsForecast, ParallelBackend, _param_descriptions, _id_as_col, make_backend\n",
"from statsforecast.core import _StatsForecast, ParallelBackend, _id_as_idx, _param_descriptions, make_backend\n",
"from statsforecast.utils import ConformalIntervals"
]
},
Expand Down Expand Up @@ -377,7 +377,7 @@
" time_col=time_col,\n",
" target_col=target_col,\n",
" )\n",
" if not _id_as_col():\n",
" if _id_as_idx():\n",
" result = result.reset_index()\n",
" return result\n",
"\n",
Expand Down Expand Up @@ -414,7 +414,7 @@
" time_col=time_col,\n",
" target_col=target_col, \n",
" )\n",
" if not _id_as_col():\n",
" if _id_as_idx():\n",
" result = result.reset_index()\n",
" return result\n",
"\n",
Expand Down Expand Up @@ -459,7 +459,7 @@
" time_col=time_col,\n",
" target_col=target_col,\n",
" )\n",
" if not _id_as_col():\n",
" if _id_as_idx():\n",
" result = result.reset_index()\n",
" return result\n",
"\n",
Expand Down
4 changes: 2 additions & 2 deletions nbs/src/feature_engineering.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
" vertical_concat,\n",
")\n",
"\n",
"import statsforecast.config as sf_config\n",
"from statsforecast import StatsForecast\n",
"from statsforecast.core import _id_as_idx\n",
"from statsforecast.models import MSTL, _predict_mstl_seas"
]
},
Expand Down Expand Up @@ -87,7 +87,7 @@
" sf = StatsForecast(models=[model], freq=freq)\n",
" sf.fit(df=df)\n",
" X_df = sf._make_future_df(h=h)\n",
" if isinstance(X_df, pd.DataFrame) and sf_config.id_as_index:\n",
" if isinstance(X_df, pd.DataFrame) and _id_as_idx():\n",
" X_df = X_df.reset_index()\n",
" train_features = []\n",
" future_features = []\n",
Expand Down
2 changes: 1 addition & 1 deletion statsforecast/_modidx.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
'statsforecast.core._StatsForecast.save': ( 'src/core/core.html#_statsforecast.save',
'statsforecast/core.py'),
'statsforecast.core._get_n_jobs': ('src/core/core.html#_get_n_jobs', 'statsforecast/core.py'),
'statsforecast.core._id_as_col': ('src/core/core.html#_id_as_col', 'statsforecast/core.py'),
'statsforecast.core._id_as_idx': ('src/core/core.html#_id_as_idx', 'statsforecast/core.py'),
'statsforecast.core._maybe_warn_sort_df': ( 'src/core/core.html#_maybe_warn_sort_df',
'statsforecast/core.py'),
'statsforecast.core._warn_df_constructor': ( 'src/core/core.html#_warn_df_constructor',
Expand Down
12 changes: 6 additions & 6 deletions statsforecast/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,8 @@ def _warn_id_as_idx():
)


def _id_as_col() -> bool:
return bool(os.getenv("NIXTLA_ID_AS_COL", ""))
def _id_as_idx() -> bool:
return not bool(os.getenv("NIXTLA_ID_AS_COL", ""))

# %% ../nbs/src/core/core.ipynb 28
_param_descriptions = {
Expand Down Expand Up @@ -648,7 +648,7 @@ def _make_future_df(self, h: int):
uids = ufp.repeat(self.uids, n=h)
df = self.df_constructor({self.id_col: uids, self.time_col: dates})
if isinstance(df, pd.DataFrame):
if not _id_as_col():
if _id_as_idx():
_warn_id_as_idx()
df = df.set_index(self.id_col)
else:
Expand Down Expand Up @@ -879,7 +879,7 @@ def forecast_fitted_values(self):
)
df[cols] = self.fcst_fitted_values_["values"]
if isinstance(df, pd.DataFrame):
if not _id_as_col():
if _id_as_idx():
_warn_id_as_idx()
df = df.set_index(self.id_col)
else:
Expand Down Expand Up @@ -1005,7 +1005,7 @@ def cross_validation(
fcsts_df = ufp.assign_columns(
fcsts_df, res_fcsts["cols"], res_fcsts["forecasts"]
)
if isinstance(fcsts_df, pd.DataFrame) and not _id_as_col():
if isinstance(fcsts_df, pd.DataFrame) and _id_as_idx():
_warn_id_as_idx()
fcsts_df = fcsts_df.set_index(id_col)
return fcsts_df
Expand Down Expand Up @@ -1051,7 +1051,7 @@ def cross_validation_fitted_values(self) -> DataFrame:
df = ufp.assign_columns(df, self.cv_fitted_values_["cols"], fitted_vals[idxs])
df = ufp.drop_index_if_pandas(df)
if isinstance(df, pd.DataFrame):
if not _id_as_col():
if _id_as_idx():
_warn_id_as_idx()
df = df.set_index(self.id_col)
else:
Expand Down
8 changes: 4 additions & 4 deletions statsforecast/distributed/fugue.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
from statsforecast.core import (
_StatsForecast,
ParallelBackend,
_id_as_idx,
_param_descriptions,
_id_as_col,
make_backend,
)
from ..utils import ConformalIntervals
Expand Down Expand Up @@ -311,7 +311,7 @@ def _forecast_series(
time_col=time_col,
target_col=target_col,
)
if not _id_as_col():
if _id_as_idx():
result = result.reset_index()
return result

Expand Down Expand Up @@ -348,7 +348,7 @@ def _forecast_series_X(
time_col=time_col,
target_col=target_col,
)
if not _id_as_col():
if _id_as_idx():
result = result.reset_index()
return result

Expand Down Expand Up @@ -393,7 +393,7 @@ def _cv(
time_col=time_col,
target_col=target_col,
)
if not _id_as_col():
if _id_as_idx():
result = result.reset_index()
return result

Expand Down
4 changes: 2 additions & 2 deletions statsforecast/feature_engineering.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
vertical_concat,
)

import statsforecast.config as sf_config
from . import StatsForecast
from .core import _id_as_idx
from .models import MSTL, _predict_mstl_seas

# %% ../nbs/src/feature_engineering.ipynb 3
Expand Down Expand Up @@ -56,7 +56,7 @@ def mstl_decomposition(
sf = StatsForecast(models=[model], freq=freq)
sf.fit(df=df)
X_df = sf._make_future_df(h=h)
if isinstance(X_df, pd.DataFrame) and sf_config.id_as_index:
if isinstance(X_df, pd.DataFrame) and _id_as_idx():
X_df = X_df.reset_index()
train_features = []
future_features = []
Expand Down

0 comments on commit fac2701

Please sign in to comment.