Repository: awslabs/gluonts

Issue #2461: GluonTS example airpassengers dataset not found
Created: 2022-11-25T10:18:35Z
am trying to run the GluonTS example code, going through some struggle to install the libraries, now I get the following error:
FileNotFoundError: C:\Users\abcde\.mxnet\gluon-ts\datasets\airpassengers\test
The C:\Users\abcde\.mxnet\gluon-ts\datasets\airpassengers\ does exist but contains only train folder. Have tried reinstalling but to no avail. Any ideas how to fix this and run the example, even if finding the dataset in correct format elsewhere?

Duplicate issue #2474: Gluon TS Fails to Get Dataset
Created: 2022-12-05T02:52:14Z
Description
Sample code from the tutorial website, https://ts.gluon.ai/stable/ does not work to import the dataset.
To Reproduce
Run this code from the tutorial as python script or the REPL console.
import matplotlib.pyplot as plt
from gluonts.dataset.util import to_pandas
from gluonts.dataset.pandas import PandasDataset
from gluonts.dataset.repository.datasets import get_dataset
from gluonts.mx import DeepAREstimator, Trainer
dataset = get_dataset("airpassengers")
Error message or code output
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In [1], line 6
      4 from gluonts.dataset.repository.datasets import get_dataset
      5 from gluonts.mx import DeepAREstimator, Trainer
----> 6 dataset = get_dataset("airpassengers")
      8 deepar = DeepAREstimator(prediction_length=12, freq="M", trainer=Trainer(epochs=5))
      9 model = deepar.train(dataset.train)

File ~/.local/lib/python3.10/site-packages/gluonts/dataset/repository/datasets.py:324, in get_dataset(dataset_name, path, regenerate, dataset_writer, prediction_length)
    280 def get_dataset(
    281     dataset_name: str,
    282     path: Path = default_dataset_path,
   (...)
    285     prediction_length: Optional[int] = None,
    286 ) -> TrainDatasets:
    287     """
    288     Get a repository dataset.
    289 
   (...)
    322         Dataset obtained by either downloading or reloading from local file.
    323     """
--> 324     dataset_path = materialize_dataset(
    325         dataset_name,
    326         path,
    327         regenerate,
    328         dataset_writer,
    329         prediction_length,
    330     )
    332     return load_datasets(
    333         metadata=dataset_path,
    334         train=dataset_path / "train",
    335         test=dataset_path / "test",
    336     )

File ~/.local/lib/python3.10/site-packages/gluonts/dataset/repository/datasets.py:271, in materialize_dataset(dataset_name, path, regenerate, dataset_writer, prediction_length)
    269         kwargs["prediction_length"] = prediction_length
    270     kwargs["dataset_writer"] = dataset_writer
--> 271     dataset_recipe(**kwargs)
    272 else:
    273     logging.info(
    274         f"using dataset already processed in path {dataset_path}."
    275     )

File ~/.local/lib/python3.10/site-packages/gluonts/dataset/repository/_airpassengers.py:47, in generate_airpassengers_dataset(dataset_path, dataset_writer)
     44 meta = MetaData(freq="1M", prediction_length=12)
     46 dataset = TrainDatasets(metadata=meta, train=train, test=test)
---> 47 dataset.save(str(dataset_path), writer=dataset_writer, overwrite=True)

File ~/.local/lib/python3.10/site-packages/gluonts/dataset/common.py:112, in TrainDatasets.save(self, path_str, writer, overwrite)
    110 train = path / "train"
    111 train.mkdir(parents=True)
--> 112 writer.write_to_folder(self.train, train)
    114 if self.test is not None:
    115     test = path / "test"

File ~/.local/lib/python3.10/site-packages/gluonts/dataset/jsonl.py:172, in JsonLinesWriter.write_to_folder(self, dataset, folder, name)
    169 else:
    170     suffix = self.suffix
--> 172 self.write_to_file(dataset, (folder / name).with_suffix(suffix))

File ~/.local/lib/python3.10/site-packages/gluonts/dataset/jsonl.py:158, in JsonLinesWriter.write_to_file(self, dataset, path)
    155     out_file = open(path, "wb")
    157 with out_file:
--> 158     for entry in dataset:
    159         json.bdump(encode_json(entry), out_file, nl=True)

File ~/.local/lib/python3.10/site-packages/gluonts/dataset/pandas.py:173, in PandasDataset.__iter__(self)
    172 def __iter__(self) -> Iterator[DataEntry]:
--> 173     for entry in self._data_entries:
    174         if self.ignore_last_n_targets:
    175             entry = prepare_prediction_data(
    176                 entry, self.ignore_last_n_targets
    177             )

File ~/.local/lib/python3.10/site-packages/gluonts/dataset/pandas.py:148, in PandasDataset._pair_to_dataentry(self, pair)
    146 if not self.unchecked:
    147     if not isinstance(df.index, pd.PeriodIndex):
--> 148         df = df.to_period(freq=self.freq)
    149     assert is_uniform(df.index), (
    150         "Dataframe index is not uniformly spaced. "
    151         "If your dataframe contains data from multiple series in the "
    152         'same column ("long" format), consider constructing the '
    153         "dataset with `PandasDataset.from_long_dataframe` instead."
    154     )
    156 data_entry = as_dataentry(
    157     data=df,
    158     target=self.target,
   (...)
    163     past_feat_dynamic_real=self.past_feat_dynamic_real,
    164 )

File ~/.local/lib/python3.10/site-packages/pandas/core/frame.py:11484, in DataFrame.to_period(self, freq, axis, copy)
  11481 if not isinstance(old_ax, DatetimeIndex):
  11482     raise TypeError(f"unsupported Type {type(old_ax).__name__}")
> 11484 new_ax = old_ax.to_period(freq=freq)
  11486 setattr(new_obj, axis_name, new_ax)
  11487 return new_obj

File ~/.local/lib/python3.10/site-packages/pandas/core/indexes/extension.py:98, in _inherit_from_data.<locals>.method(self, *args, **kwargs)
     96 if "inplace" in kwargs:
     97     raise ValueError(f"cannot use inplace with {type(self).__name__}")
---> 98 result = attr(self._data, *args, **kwargs)
     99 if wrap:
    100     if isinstance(result, type(self._data)):

File ~/.local/lib/python3.10/site-packages/pandas/core/arrays/datetimes.py:1137, in DatetimeArray.to_period(self, freq)
   1133         res = freq
   1135     freq = res
-> 1137 return PeriodArray._from_datetime64(self._ndarray, freq, tz=self.tz)

File ~/.local/lib/python3.10/site-packages/pandas/core/arrays/period.py:298, in PeriodArray._from_datetime64(cls, data, freq, tz)
    283 @classmethod
    284 def _from_datetime64(cls, data, freq, tz=None) -> PeriodArray:
    285     """
    286     Construct a PeriodArray from a datetime64 array
    287 
   (...)
    296     PeriodArray[freq]
    297     """
--> 298     data, freq = dt64arr_to_periodarr(data, freq, tz)
    299     return cls(data, freq=freq)

File ~/.local/lib/python3.10/site-packages/pandas/core/arrays/period.py:1066, in dt64arr_to_periodarr(data, freq, tz)
   1064 reso = get_unit_from_dtype(data.dtype)
   1065 freq = Period._maybe_convert_freq(freq)
-> 1066 base = freq._period_dtype_code
   1067 return c_dt64arr_to_periodarr(data.view("i8"), base, tz, reso=reso), freq

AttributeError: 'pandas._libs.tslibs.offsets.MonthBegin' object has no attribute '_period_dtype_code'

Environment

Operating system: Ubuntu 22.04
Python version: 3.10.6
GluonTS version: 0.11.3
MXNet version: 1.9.1
Pandas version: 1.5.1

Closing comment (2022-12-05T13:36:38Z): Hi, thanks for raising the issue. This is a duplicate of #2461 and the fix is pending release.