autogluon.timeseries 1.1.2b20241016__py3-none-any.whl → 1.1.2b20241018__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,6 +7,7 @@ import reprlib
7
7
  from collections.abc import Iterable
8
8
  from itertools import islice
9
9
  from pathlib import Path
10
+ from pprint import pformat
10
11
  from typing import Any, List, Optional, Tuple, Type, Union
11
12
 
12
13
  import pandas as pd
@@ -476,28 +477,82 @@ class TimeSeriesDataFrame(pd.DataFrame, TimeSeriesDataFrameDeprecatedMixin):
476
477
 
477
478
  self._static_features = value
478
479
 
480
+ def infer_frequency(self, num_items: Optional[int] = 100, raise_if_irregular: bool = False) -> str:
481
+ """Infer the time series frequency based on the timestamps of the observations.
482
+
483
+ Parameters
484
+ ----------
485
+ num_items : int or None, default = 100
486
+ Number of items (individual time series) randomly selected to infer the frequency. Lower values speed up
487
+ the method, but increase the chance that some items with invalid frequency are missed by subsampling.
488
+
489
+ If set to `None`, all items will be used for inferring the frequency.
490
+ raise_if_irregular : bool, default = False
491
+ If True, an exception will be raised if some items have an irregular frequency, or if different items have
492
+ different frequencies.
493
+
494
+ Returns
495
+ -------
496
+ freq : str
497
+ If all time series have a regular frequency, returns a pandas-compatible `frequency alias <https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases>`_.
498
+
499
+ If some items have an irregular frequency or if different items have different frequencies, returns string
500
+ `IRREG`.
501
+ """
502
+
503
+ df = pd.DataFrame(self)
504
+ if num_items is not None:
505
+ all_item_ids = self.item_ids
506
+ if len(all_item_ids) > num_items:
507
+ items_subset = all_item_ids.to_series().sample(n=num_items, random_state=123)
508
+ df = df.loc[items_subset]
509
+
510
+ candidate_freq = df.index.levels[1].freq
511
+ index_df = df.index.to_frame(index=False)
512
+
513
+ def get_freq(series: pd.Series) -> Optional[str]:
514
+ dt_index = pd.DatetimeIndex(series)
515
+ inferred_freq = dt_index.inferred_freq
516
+ # Fallback option: maybe original index has a `freq` attribute that pandas fails to infer (e.g., 'SME')
517
+ if inferred_freq is None and candidate_freq is not None:
518
+ try:
519
+ # If this line does not raise an exception, then candidate_freq is a compatible frequency
520
+ dt_index.freq = candidate_freq
521
+ except ValueError:
522
+ inferred_freq = None
523
+ else:
524
+ inferred_freq = candidate_freq
525
+ return inferred_freq
526
+
527
+ freq_for_each_item = index_df.groupby(ITEMID, sort=False).agg(get_freq)[TIMESTAMP]
528
+ freq = freq_for_each_item.iloc[0]
529
+ if len(set(freq_for_each_item)) > 1 or freq is None:
530
+ if raise_if_irregular:
531
+ items_with_irregular_freq = freq_for_each_item[pd.isnull(freq_for_each_item)]
532
+ if len(items_with_irregular_freq) > 0:
533
+ raise ValueError(
534
+ "Cannot infer frequency. Items with irregular frequency: "
535
+ f"{pformat(items_with_irregular_freq.index.tolist())}"
536
+ )
537
+ else:
538
+ raise ValueError(
539
+ "Cannot infer frequency. Multiple frequencies detected in the dataset: "
540
+ f"{freq_for_each_item.unique().tolist()}"
541
+ )
542
+ return IRREGULAR_TIME_INDEX_FREQSTR
543
+ else:
544
+ return pd.tseries.frequencies.to_offset(freq).freqstr
545
+
479
546
  @property
480
547
  def freq(self):
481
- if self._cached_freq is not None and self._cached_freq == IRREGULAR_TIME_INDEX_FREQSTR:
548
+ if self._cached_freq is None:
549
+ self._cached_freq = self.infer_frequency()
550
+
551
+ if self._cached_freq == IRREGULAR_TIME_INDEX_FREQSTR:
482
552
  return None # irregularly sampled time series
483
- elif self._cached_freq:
553
+ else:
484
554
  return self._cached_freq
485
555
 
486
- def get_freq(series):
487
- return series.index.freq or series.index.inferred_freq
488
-
489
- # check the frequencies of the first 100 items to see if frequencies are consistent and
490
- # can be inferred
491
- freq_for_each_series = [get_freq(self.loc[idx]) for idx in self.item_ids[:100]]
492
- freq = freq_for_each_series[0]
493
- if len(set(freq_for_each_series)) > 1 or freq is None:
494
- self._cached_freq = IRREGULAR_TIME_INDEX_FREQSTR
495
- return None
496
-
497
- freq = freq.freqstr if isinstance(freq, pd._libs.tslibs.BaseOffset) else freq
498
- self._cached_freq = freq
499
- return freq
500
-
501
556
  @property
502
557
  def num_items(self):
503
558
  return len(self.item_ids)
@@ -252,7 +252,7 @@ class TimeSeriesPredictor(TimeSeriesPredictorDeprecatedMixin):
252
252
  self,
253
253
  data: Union[TimeSeriesDataFrame, pd.DataFrame, Path, str],
254
254
  name: str = "data",
255
- ) -> "TimeSeriesDataFrame":
255
+ ) -> TimeSeriesDataFrame:
256
256
  if isinstance(data, TimeSeriesDataFrame):
257
257
  return data
258
258
  elif isinstance(data, (pd.DataFrame, Path, str)):
@@ -299,7 +299,10 @@ class TimeSeriesPredictor(TimeSeriesPredictorDeprecatedMixin):
299
299
 
300
300
  # Ensure that data has a regular frequency that matches the predictor frequency
301
301
  if self.freq is None:
302
- if df.freq is None:
302
+ try:
303
+ # Use all items for inferring the frequency
304
+ self.freq = df.infer_frequency(num_items=None, raise_if_irregular=True)
305
+ except ValueError:
303
306
  raise ValueError(
304
307
  f"Frequency of {name} is not provided and cannot be inferred. Please set the expected data "
305
308
  f"frequency when creating the predictor with `TimeSeriesPredictor(freq=...)` or ensure that "
@@ -1,3 +1,3 @@
1
1
  """This is the autogluon version file."""
2
- __version__ = '1.1.2b20241016'
2
+ __version__ = '1.1.2b20241018'
3
3
  __lite__ = False
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: autogluon.timeseries
3
- Version: 1.1.2b20241016
3
+ Version: 1.1.2b20241018
4
4
  Summary: Fast and Accurate ML in 3 Lines of Code
5
5
  Home-page: https://github.com/autogluon/autogluon
6
6
  Author: AutoGluon Community
@@ -52,9 +52,9 @@ Requires-Dist: fugue>=0.9.0
52
52
  Requires-Dist: tqdm<5,>=4.38
53
53
  Requires-Dist: orjson~=3.9
54
54
  Requires-Dist: tensorboard<3,>=2.9
55
- Requires-Dist: autogluon.core[raytune]==1.1.2b20241016
56
- Requires-Dist: autogluon.common==1.1.2b20241016
57
- Requires-Dist: autogluon.tabular[catboost,lightgbm,xgboost]==1.1.2b20241016
55
+ Requires-Dist: autogluon.core[raytune]==1.1.2b20241018
56
+ Requires-Dist: autogluon.common==1.1.2b20241018
57
+ Requires-Dist: autogluon.tabular[catboost,lightgbm,xgboost]==1.1.2b20241018
58
58
  Provides-Extra: all
59
59
  Requires-Dist: optimum[onnxruntime]<1.19,>=1.17; extra == "all"
60
60
  Provides-Extra: chronos-onnx
@@ -1,14 +1,14 @@
1
- autogluon.timeseries-1.1.2b20241016-py3.8-nspkg.pth,sha256=cQGwpuGPqg1GXscIwt-7PmME1OnSpD-7ixkikJ31WAY,554
1
+ autogluon.timeseries-1.1.2b20241018-py3.8-nspkg.pth,sha256=cQGwpuGPqg1GXscIwt-7PmME1OnSpD-7ixkikJ31WAY,554
2
2
  autogluon/timeseries/__init__.py,sha256=_CrLLc1fkjen7UzWoO0Os8WZoHOgvZbHKy46I8v_4k4,304
3
3
  autogluon/timeseries/evaluator.py,sha256=l642tYfTHsl8WVIq_vV6qhgAFVFr9UuZD7gLra3A_Kc,250
4
4
  autogluon/timeseries/learner.py,sha256=NXhftyqMD8Bl1QHIBN82UKP0UlCV_ACughZqkmMf4oY,14043
5
- autogluon/timeseries/predictor.py,sha256=3HdPaxvhS-FatQ0Rf5xvMw5NgU3BXlt8m8nwRgC-b2U,84399
5
+ autogluon/timeseries/predictor.py,sha256=BUjFX5I_tgim9oo43cRgLBAxKY1JfduKtHQxY8BPC-Y,84561
6
6
  autogluon/timeseries/splitter.py,sha256=eghGwAAN2_cxGk5aJBILgjGWtLzjxJcytMy49gg_q18,3061
7
- autogluon/timeseries/version.py,sha256=lDd_TludjpIJTs7S7Uij_tnVikz8lmKZCbK6TpyU69k,90
7
+ autogluon/timeseries/version.py,sha256=vN9WGRyG5Ww78Etq6u3pGSVbJRy2Z_B1iLwyBmf5mNY,90
8
8
  autogluon/timeseries/configs/__init__.py,sha256=BTtHIPCYeGjqgOcvqb8qPD4VNX-ICKOg6wnkew1cPOE,98
9
9
  autogluon/timeseries/configs/presets_configs.py,sha256=94-yL9teDHKs2irWjP3kpewI7FE1ChYCgEgz9XHJ6gc,1965
10
10
  autogluon/timeseries/dataset/__init__.py,sha256=UvnhAN5tjgxXTHoZMQDy64YMDj4Xxa68yY7NP4vAw0o,81
11
- autogluon/timeseries/dataset/ts_dataframe.py,sha256=QgCwzRx10CRzeWzQREX_zUDAl77-lkdNjM0bT3kK8NU,45595
11
+ autogluon/timeseries/dataset/ts_dataframe.py,sha256=w7wEue_ZALNmvkGSEAnYE-jqbGj8fdsT9YvHpGY9URY,48296
12
12
  autogluon/timeseries/metrics/__init__.py,sha256=KzgXNj5or7RB_uadjgC8p5gxyV26zjj2hT58OmvnfmA,1875
13
13
  autogluon/timeseries/metrics/abstract.py,sha256=9xCFQ3NaR1C0hn01M7oBd72a_CiNV-w6QFcRjwUbKYI,8183
14
14
  autogluon/timeseries/metrics/point.py,sha256=xy8sKrBbuxZ7yTW21TDPayKnEj2FBj1AEseJxUdneqE,13399
@@ -55,11 +55,11 @@ autogluon/timeseries/utils/datetime/base.py,sha256=3NdsH3NDq4cVAOSoy3XpaNixyNlbj
55
55
  autogluon/timeseries/utils/datetime/lags.py,sha256=GoLtvcZ8oKb3QkoBJ9E59LSPLOP7Qjxrr2UmMSZgjyw,5909
56
56
  autogluon/timeseries/utils/datetime/seasonality.py,sha256=h_4w00iEytAz_N_EpCENQ8RCXy7KQITczrYjBgVqWkQ,764
57
57
  autogluon/timeseries/utils/datetime/time_features.py,sha256=PAXbYbQ0z_5GFbkxSNi41zLY_2-U3x0Ynm1m_WhdtGc,2572
58
- autogluon.timeseries-1.1.2b20241016.dist-info/LICENSE,sha256=CeipvOyAZxBGUsFoaFqwkx54aPnIKEtm9a5u2uXxEws,10142
59
- autogluon.timeseries-1.1.2b20241016.dist-info/METADATA,sha256=7SY4Fl3Jx7tF8O-a9EZmiko_uVUOP-eiworItj8xwJs,12355
60
- autogluon.timeseries-1.1.2b20241016.dist-info/NOTICE,sha256=7nPQuj8Kp-uXsU0S5so3-2dNU5EctS5hDXvvzzehd7E,114
61
- autogluon.timeseries-1.1.2b20241016.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
62
- autogluon.timeseries-1.1.2b20241016.dist-info/namespace_packages.txt,sha256=giERA4R78OkJf2ijn5slgjURlhRPzfLr7waIcGkzYAo,10
63
- autogluon.timeseries-1.1.2b20241016.dist-info/top_level.txt,sha256=giERA4R78OkJf2ijn5slgjURlhRPzfLr7waIcGkzYAo,10
64
- autogluon.timeseries-1.1.2b20241016.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
65
- autogluon.timeseries-1.1.2b20241016.dist-info/RECORD,,
58
+ autogluon.timeseries-1.1.2b20241018.dist-info/LICENSE,sha256=CeipvOyAZxBGUsFoaFqwkx54aPnIKEtm9a5u2uXxEws,10142
59
+ autogluon.timeseries-1.1.2b20241018.dist-info/METADATA,sha256=tHt8_6riIMPcLakUBZ7zCHVMIsQl15u0x2lFa9hDFTQ,12355
60
+ autogluon.timeseries-1.1.2b20241018.dist-info/NOTICE,sha256=7nPQuj8Kp-uXsU0S5so3-2dNU5EctS5hDXvvzzehd7E,114
61
+ autogluon.timeseries-1.1.2b20241018.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
62
+ autogluon.timeseries-1.1.2b20241018.dist-info/namespace_packages.txt,sha256=giERA4R78OkJf2ijn5slgjURlhRPzfLr7waIcGkzYAo,10
63
+ autogluon.timeseries-1.1.2b20241018.dist-info/top_level.txt,sha256=giERA4R78OkJf2ijn5slgjURlhRPzfLr7waIcGkzYAo,10
64
+ autogluon.timeseries-1.1.2b20241018.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
65
+ autogluon.timeseries-1.1.2b20241018.dist-info/RECORD,,