Skip to content

Commit

Permalink
deps(pandas): address frequency alias deprecations in `generate_serie…
Browse files Browse the repository at this point in the history
…s` (#139)
  • Loading branch information
jmoralez authored Nov 28, 2024
1 parent 05d7947 commit 0afcf9a
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 44 deletions.
14 changes: 0 additions & 14 deletions nbs/compat.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,6 @@
" POLARS_INSTALLED = False\n",
"\n",
"try:\n",
" import plotly # noqa: F401\n",
"\n",
" PLOTLY_INSTALLED = True\n",
"except ImportError:\n",
" PLOTLY_INSTALLED = False\n",
"\n",
"try:\n",
" import plotly_resampler # noqa: F401\n",
"\n",
" PLOTLY_RESAMPLER_INSTALLED = True\n",
"except ImportError:\n",
" PLOTLY_RESAMPLER_INSTALLED = False\n",
"\n",
"try:\n",
" from numba import njit # noqa: F04\n",
"except ImportError:\n",
" def _doublewrap(f):\n",
Expand Down
25 changes: 15 additions & 10 deletions nbs/data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@
" Number of series for synthetic panel.\n",
" freq : str (default='D')\n",
" Frequency of the data (pandas alias).\n",
" Seasonalities are implemented for 'H', 'D' and 'M'.\n",
" Seasonalities are implemented for hourly, daily and monthly.\n",
" min_length : int (default=50)\n",
" Minimum length of synthetic panel's series.\n",
" max_length : int (default=500)\n",
" Maximum length of synthetic panel's series.\n",
" n_static_features : int (default=0)\n",
" Number of static exogenous variables for synthetic panel's series.\n",
" equal_ends : bool (default=False)\n",
" Series should end in the same date stamp `ds`.\n",
" Series should end in the same timestamp.\n",
" with_trend : bool (default=False)\n",
" Series should have a (positive) trend.\n",
" static_as_categorical : bool (default=True)\n",
Expand All @@ -151,10 +151,15 @@
" raise ValueError(\n",
" f\"{engine} is not a correct engine; available options: {available_engines}\"\n",
" )\n",
" seasonalities = {'H': 24, 'D': 7, 'M': 12}\n",
" season = seasonalities.get(freq, 1)\n",
" freq = pd.tseries.frequencies.to_offset(freq) \n",
" \n",
" seasonalities = {\n",
" pd.offsets.Hour(): 24,\n",
" pd.offsets.Day(): 7,\n",
" pd.offsets.MonthBegin(): 12,\n",
" pd.offsets.MonthEnd(): 12,\n",
" }\n",
" freq = pd.tseries.frequencies.to_offset(freq)\n",
" season = seasonalities.get(freq, 1) \n",
"\n",
" rng = np.random.RandomState(seed)\n",
" series_lengths = rng.randint(min_length, max_length + 1, n_series)\n",
" total_length = series_lengths.sum()\n",
Expand Down Expand Up @@ -234,11 +239,11 @@
"| | **Type** | **Default** | **Details** |\n",
"| -- | -------- | ----------- | ----------- |\n",
"| n_series | int | | Number of series for synthetic panel. |\n",
"| freq | str | D | Frequency of the data (pandas alias).<br>Seasonalities are implemented for 'H', 'D' and 'M'. |\n",
"| freq | str | D | Frequency of the data (pandas alias).<br>Seasonalities are implemented for hourly, daily and monthly. |\n",
"| min_length | int | 50 | Minimum length of synthetic panel's series. |\n",
"| max_length | int | 500 | Maximum length of synthetic panel's series. |\n",
"| n_static_features | int | 0 | Number of static exogenous variables for synthetic panel's series. |\n",
"| equal_ends | bool | False | Series should end in the same date stamp `ds`. |\n",
"| equal_ends | bool | False | Series should end in the same timestamp. |\n",
"| with_trend | bool | False | Series should have a (positive) trend. |\n",
"| static_as_categorical | bool | True | Static features should have a categorical data type. |\n",
"| n_models | int | 0 | Number of models predictions to simulate. |\n",
Expand Down Expand Up @@ -266,11 +271,11 @@
"| | **Type** | **Default** | **Details** |\n",
"| -- | -------- | ----------- | ----------- |\n",
"| n_series | int | | Number of series for synthetic panel. |\n",
"| freq | str | D | Frequency of the data (pandas alias).<br>Seasonalities are implemented for 'H', 'D' and 'M'. |\n",
"| freq | str | D | Frequency of the data (pandas alias).<br>Seasonalities are implemented for hourly, daily and monthly. |\n",
"| min_length | int | 50 | Minimum length of synthetic panel's series. |\n",
"| max_length | int | 500 | Maximum length of synthetic panel's series. |\n",
"| n_static_features | int | 0 | Number of static exogenous variables for synthetic panel's series. |\n",
"| equal_ends | bool | False | Series should end in the same date stamp `ds`. |\n",
"| equal_ends | bool | False | Series should end in the same timestamp. |\n",
"| with_trend | bool | False | Series should have a (positive) trend. |\n",
"| static_as_categorical | bool | True | Static features should have a categorical data type. |\n",
"| n_models | int | 0 | Number of models predictions to simulate. |\n",
Expand Down
Binary file modified nbs/imgs/plotting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 12 additions & 2 deletions nbs/plotting.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -632,10 +632,20 @@
"\n",
"from fastcore.test import test_fail\n",
"\n",
"from utilsforecast.compat import POLARS_INSTALLED, PLOTLY_INSTALLED, PLOTLY_RESAMPLER_INSTALLED\n",
"from utilsforecast.compat import POLARS_INSTALLED\n",
"\n",
"if POLARS_INSTALLED:\n",
" import polars as pl"
" import polars as pl\n",
"try:\n",
" import plotly\n",
" PLOTLY_INSTALLED = True\n",
"except ImportError:\n",
" PLOTLY_INSTALLED = False\n",
"try:\n",
" import plotly_resampler\n",
" PLOTLY_RESAMPLER_INSTALLED = True\n",
"except ImportError:\n",
" PLOTLY_RESAMPLER_INSTALLED = False"
]
},
{
Expand Down
14 changes: 0 additions & 14 deletions utilsforecast/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,6 @@ class pl_Series: ...
DFType = pd.DataFrame
POLARS_INSTALLED = False

try:
import plotly # noqa: F401

PLOTLY_INSTALLED = True
except ImportError:
PLOTLY_INSTALLED = False

try:
import plotly_resampler # noqa: F401

PLOTLY_RESAMPLER_INSTALLED = True
except ImportError:
PLOTLY_RESAMPLER_INSTALLED = False

try:
from numba import njit # noqa: F04
except ImportError:
Expand Down
13 changes: 9 additions & 4 deletions utilsforecast/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ def generate_series(
Number of series for synthetic panel.
freq : str (default='D')
Frequency of the data (pandas alias).
Seasonalities are implemented for 'H', 'D' and 'M'.
Seasonalities are implemented for hourly, daily and monthly.
min_length : int (default=50)
Minimum length of synthetic panel's series.
max_length : int (default=500)
Maximum length of synthetic panel's series.
n_static_features : int (default=0)
Number of static exogenous variables for synthetic panel's series.
equal_ends : bool (default=False)
Series should end in the same date stamp `ds`.
Series should end in the same timestamp.
with_trend : bool (default=False)
Series should have a (positive) trend.
static_as_categorical : bool (default=True)
Expand All @@ -99,9 +99,14 @@ def generate_series(
raise ValueError(
f"{engine} is not a correct engine; available options: {available_engines}"
)
seasonalities = {"H": 24, "D": 7, "M": 12}
season = seasonalities.get(freq, 1)
seasonalities = {
pd.offsets.Hour(): 24,
pd.offsets.Day(): 7,
pd.offsets.MonthBegin(): 12,
pd.offsets.MonthEnd(): 12,
}
freq = pd.tseries.frequencies.to_offset(freq)
season = seasonalities.get(freq, 1)

rng = np.random.RandomState(seed)
series_lengths = rng.randint(min_length, max_length + 1, n_series)
Expand Down

0 comments on commit 0afcf9a

Please sign in to comment.