code: def test_dataset_statistics_exceptions(self) -> None:
      def check_error_message(expected_regex, dataset) -> None:
          with self.assertRaisesRegex(GluonTSDataError, expected_regex):
              calculate_dataset_statistics(dataset)
  
      check_error_message("Time series dataset is empty!", [])
  
      check_error_message(
          "Only empty time series found in the dataset!",
          [make_time_series(target=np.random.randint(0, 10, 0))],
      )
  
      # infinite target
      # check_error_message(
      #     "Target values have to be finite (e.g., not inf, -inf, "
      #     "or None) and cannot exceed single precision floating "
      #     "point range.",
      #     [make_time_series(target=np.full(20, np.inf))]
      # )
  
      # different number of feat_dynamic_{cat, real}
      check_error_message(
          "Found instances with different number of features in "
          "feat_dynamic_cat, found one with 2 and another with 1.",
          [
              make_time_series(num_feat_dynamic_cat=2),
              make_time_series(num_feat_dynamic_cat=1),
          ],
      )
      check_error_message(
          "Found instances with different number of features in "
          "feat_dynamic_cat, found one with 0 and another with 1.",
          [
              make_time_series(num_feat_dynamic_cat=0),
              make_time_series(num_feat_dynamic_cat=1),
          ],
      )
      check_error_message(
          "feat_dynamic_cat was found for some instances but not others.",
          [
              make_time_series(num_feat_dynamic_cat=1),
              make_time_series(num_feat_dynamic_cat=0),
          ],
      )
      check_error_message(
          "Found instances with different number of features in "
          "feat_dynamic_real, found one with 2 and another with 1.",
          [
              make_time_series(num_feat_dynamic_real=2),
              make_time_series(num_feat_dynamic_real=1),
          ],
      )
      check_error_message(
          "Found instances with different number of features in "
          "feat_dynamic_real, found one with 0 and another with 1.",
          [
              make_time_series(num_feat_dynamic_real=0),
              make_time_series(num_feat_dynamic_real=1),
          ],
      )
      check_error_message(
          "feat_dynamic_real was found for some instances but not others.",
          [
              make_time_series(num_feat_dynamic_real=1),
              make_time_series(num_feat_dynamic_real=0),
          ],
      )
  
      # infinite feat_dynamic_{cat,real}
      inf_dynamic_feat = np.full((2, len(target)), np.inf)
      check_error_message(
          "Features values have to be finite and cannot exceed single "
          "precision floating point range.",
          [
              ts(
                  start,
                  target,
                  feat_dynamic_cat=inf_dynamic_feat,
                  feat_static_cat=[0, 1],
              )
          ],
      )
      check_error_message(
          "Features values have to be finite and cannot exceed single "
          "precision floating point range.",
          [
              ts(
                  start,
                  target,
                  feat_dynamic_real=inf_dynamic_feat,
                  feat_static_cat=[0, 1],
              )
          ],
      )
  
      # feat_dynamic_{cat, real} different length from target
      check_error_message(
          "Each feature in feat_dynamic_cat has to have the same length as the "
          "target. Found an instance with feat_dynamic_cat of length 1 and a "
          "target of length 20.",
          [
              ts(
                  start=start,
                  target=target,
                  feat_static_cat=[0, 1],
                  feat_dynamic_cat=np.ones((1, 1)),
              )
          ],
      )
      check_error_message(
          "Each feature in feat_dynamic_real has to have the same length as the "
          "target. Found an instance with feat_dynamic_real of length 1 and a "
          "target of length 20.",
          [
              ts(
                  start=start,
                  target=target,
                  feat_static_cat=[0, 1],
                  feat_dynamic_real=np.ones((1, 1)),
              )
          ],
      )
  
      # feat_static_{cat, real} different length
      check_error_message(
          "Not all feat_static_cat vectors have the same length 2 != 1.",
          [
              ts(start=start, target=target, feat_static_cat=[0, 1]),
              ts(start=start, target=target, feat_static_cat=[1]),
          ],
      )
      check_error_message(
          "Not all feat_static_real vectors have the same length 2 != 1.",
          [
              ts(start=start, target=target, feat_static_real=[0, 1]),
              ts(start=start, target=target, feat_static_real=[1]),
          ],
      )
  
      calculate_dataset_statistics(
          # FIXME: the cast below is a hack to make mypy happy
          cast(
              Dataset,
              [
                  make_time_series(num_feat_dynamic_cat=2),
                  make_time_series(num_feat_dynamic_cat=2),
              ],
          )
      )
  
      calculate_dataset_statistics(
          # FIXME: the cast below is a hack to make mypy happy
          cast(
              Dataset,
              [
                  make_time_series(num_feat_dynamic_cat=0),
                  make_time_series(num_feat_dynamic_cat=0),
              ],
          )
      )
  
file_path: gluonts/test/dataset/test_stat.py
imports: import unittest
  from typing import cast
  import numpy
  import pandas
  from gluonts.dataset.common import DataEntry, Dataset
  from gluonts.dataset.stat import DatasetStatistics, ScaleHistogram, calculate_dataset_statistics
  from gluonts.exceptions import GluonTSDataError
label_desc: Use image node_id 1 for calling the DatasetStatisticsExceptions obj's underlying member method code with example usage: obj.test_dataset_statistics_exceptions() without return types