diff --git a/nbs/compat.ipynb b/nbs/compat.ipynb index 1159d01..40600c6 100644 --- a/nbs/compat.ipynb +++ b/nbs/compat.ipynb @@ -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", diff --git a/nbs/data.ipynb b/nbs/data.ipynb index d24d9be..f077059 100644 --- a/nbs/data.ipynb +++ b/nbs/data.ipynb @@ -118,7 +118,7 @@ " 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", @@ -126,7 +126,7 @@ " 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", @@ -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", @@ -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).
Seasonalities are implemented for 'H', 'D' and 'M'. |\n", + "| freq | str | D | Frequency of the data (pandas alias).
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", @@ -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).
Seasonalities are implemented for 'H', 'D' and 'M'. |\n", + "| freq | str | D | Frequency of the data (pandas alias).
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", diff --git a/nbs/imgs/plotting.png b/nbs/imgs/plotting.png index 5900486..c75473c 100644 Binary files a/nbs/imgs/plotting.png and b/nbs/imgs/plotting.png differ diff --git a/nbs/plotting.ipynb b/nbs/plotting.ipynb index a8821d5..0e6a674 100644 --- a/nbs/plotting.ipynb +++ b/nbs/plotting.ipynb @@ -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" ] }, { diff --git a/utilsforecast/compat.py b/utilsforecast/compat.py index 0aba443..2f1815d 100644 --- a/utilsforecast/compat.py +++ b/utilsforecast/compat.py @@ -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: diff --git a/utilsforecast/data.py b/utilsforecast/data.py index 16b469d..a7afaef 100644 --- a/utilsforecast/data.py +++ b/utilsforecast/data.py @@ -66,7 +66,7 @@ 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) @@ -74,7 +74,7 @@ def generate_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) @@ -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)