class_docstr: PyTorch Dataset for fitting timeseries models.
  
  The dataset automates common tasks such as
  
  * scaling and encoding of variables
  * normalizing the target variable
  * efficiently converting timeseries in pandas dataframes to torch tensors
  * holding information about static and time-varying variables known and unknown in the future
  * holiding information about related categories (such as holidays)
  * downsampling for data augmentation
  * generating inference, validation and test datasets
  * etc.
class_docstr_tok: ["PyTorch","Dataset","for","fitting","timeseries","models",".","The","dataset","automates","common","tasks","such","as","*","scaling","and","encoding","of","variables","*","normalizing","the","target","variable","*","efficiently","converting","timeseries","in","pandas","dataframes","to","torch","tensors","*","holding","information","about","static","and","time-varying","variables","known","and","unknown","in","the","future","*","holiding","information","about","related","categories","(","such","as","holidays",")","*","downsampling","for","data","augmentation","*","generating","inference",",","validation","and","test","datasets","*","etc","."]
docstr: Get dataloader from dataset.
  
  The
  
  Args:
      train (bool, optional): if dataloader is used for training or prediction
          Will shuffle and drop last batch if True. Defaults to True.
      batch_size (int): batch size for training model. Defaults to 64.
      batch_sampler (Union[Sampler, str]): batch sampler or string. One of
  
          * "synchronized": ensure that samples in decoder are aligned in time. Does not support missing
            values in dataset. This makes only sense if the underlying algorithm makes use of values aligned
            in time.
          * PyTorch Sampler instance: any PyTorch sampler, e.g. the WeightedRandomSampler()
          * None: samples are taken randomly from times series.
  
      **kwargs: additional arguments to ``DataLoader()``
  
  Returns:
      DataLoader: dataloader that returns Tuple.
          First entry is ``x``, a dictionary of tensors with the entries (and shapes in brackets)
  
          * encoder_cat (batch_size x n_encoder_time_steps x n_features): long tensor of encoded
            categoricals for encoder
          * encoder_cont (batch_size x n_encoder_time_steps x n_features): float tensor of scaled continuous
            variables for encoder
          * encoder_target (batch_size x n_encoder_time_steps or list thereof with each entry for a different
            target):
            float tensor with unscaled continous target or encoded categorical target,
            list of tensors for multiple targets
          * encoder_lengths (batch_size): long tensor with lengths of the encoder time series. No entry will
            be greater than n_encoder_time_steps
          * decoder_cat (batch_size x n_decoder_time_steps x n_features): long tensor of encoded
            categoricals for decoder
          * decoder_cont (batch_size x n_decoder_time_steps x n_features): float tensor of scaled continuous
            variables for decoder
          * decoder_target (batch_size x n_decoder_time_steps or list thereof with each entry for a different
            target):
            float tensor with unscaled continous target or encoded categorical target for decoder
            - this corresponds to first entry of ``y``, list of tensors for multiple targets
          * decoder_lengths (batch_size): long tensor with lengths of the decoder time series. No entry will
            be greater than n_decoder_time_steps
          * group_ids (batch_size x number_of_ids): encoded group ids that identify a time series in the dataset
          * target_scale (batch_size x scale_size or list thereof with each entry for a different target):
            parameters used to normalize the target.
            Typically these are mean and standard deviation. Is list of tensors for multiple targets.
  
  
          Second entry is ``y``, a tuple of the form (``target``, `weight`)
  
          * target (batch_size x n_decoder_time_steps or list thereof with each entry for a different target):
            unscaled (continuous) or encoded (categories) targets, list of tensors for multiple targets
          * weight (None or batch_size x n_decoder_time_steps): weight
  
  Example:
  
      Weight by samples for training:
  
      .. code-block:: python
  
          from torch.utils.data import WeightedRandomSampler
  
          # length of probabilties for sampler have to be equal to the length of the index
          probabilities = np.sqrt(1 + data.loc[dataset.index, "target"])
          sampler = WeightedRandomSampler(probabilities, len(probabilities))
          dataset.to_dataloader(train=True, sampler=sampler, shuffle=False)
code: def to_dataloader(
      self,
      train: bool = True,
      batch_size: int = 64,
      batch_sampler: Union[Sampler, str] = None,
      **kwargs,
  ) -> DataLoader:
      """
      Get dataloader from dataset.
  
      The
  
      Args:
          train (bool, optional): if dataloader is used for training or prediction
              Will shuffle and drop last batch if True. Defaults to True.
          batch_size (int): batch size for training model. Defaults to 64.
          batch_sampler (Union[Sampler, str]): batch sampler or string. One of
  
              * "synchronized": ensure that samples in decoder are aligned in time. Does not support missing
                values in dataset. This makes only sense if the underlying algorithm makes use of values aligned
                in time.
              * PyTorch Sampler instance: any PyTorch sampler, e.g. the WeightedRandomSampler()
              * None: samples are taken randomly from times series.
  
          **kwargs: additional arguments to ``DataLoader()``
  
      Returns:
          DataLoader: dataloader that returns Tuple.
              First entry is ``x``, a dictionary of tensors with the entries (and shapes in brackets)
  
              * encoder_cat (batch_size x n_encoder_time_steps x n_features): long tensor of encoded
                categoricals for encoder
              * encoder_cont (batch_size x n_encoder_time_steps x n_features): float tensor of scaled continuous
                variables for encoder
              * encoder_target (batch_size x n_encoder_time_steps or list thereof with each entry for a different
                target):
                float tensor with unscaled continous target or encoded categorical target,
                list of tensors for multiple targets
              * encoder_lengths (batch_size): long tensor with lengths of the encoder time series. No entry will
                be greater than n_encoder_time_steps
              * decoder_cat (batch_size x n_decoder_time_steps x n_features): long tensor of encoded
                categoricals for decoder
              * decoder_cont (batch_size x n_decoder_time_steps x n_features): float tensor of scaled continuous
                variables for decoder
              * decoder_target (batch_size x n_decoder_time_steps or list thereof with each entry for a different
                target):
                float tensor with unscaled continous target or encoded categorical target for decoder
                - this corresponds to first entry of ``y``, list of tensors for multiple targets
              * decoder_lengths (batch_size): long tensor with lengths of the decoder time series. No entry will
                be greater than n_decoder_time_steps
              * group_ids (batch_size x number_of_ids): encoded group ids that identify a time series in the dataset
              * target_scale (batch_size x scale_size or list thereof with each entry for a different target):
                parameters used to normalize the target.
                Typically these are mean and standard deviation. Is list of tensors for multiple targets.
  
  
              Second entry is ``y``, a tuple of the form (``target``, `weight`)
  
              * target (batch_size x n_decoder_time_steps or list thereof with each entry for a different target):
                unscaled (continuous) or encoded (categories) targets, list of tensors for multiple targets
              * weight (None or batch_size x n_decoder_time_steps): weight
  
      Example:
  
          Weight by samples for training:
  
          .. code-block:: python
  
              from torch.utils.data import WeightedRandomSampler
  
              # length of probabilties for sampler have to be equal to the length of the index
              probabilities = np.sqrt(1 + data.loc[dataset.index, "target"])
              sampler = WeightedRandomSampler(probabilities, len(probabilities))
              dataset.to_dataloader(train=True, sampler=sampler, shuffle=False)
      """
      default_kwargs = dict(
          shuffle=train,
          drop_last=train and len(self) > batch_size,
          collate_fn=self._collate_fn,
          batch_size=batch_size,
          batch_sampler=batch_sampler,
      )
      default_kwargs.update(kwargs)
      kwargs = default_kwargs
      if kwargs["batch_sampler"] is not None:
          sampler = kwargs["batch_sampler"]
          if isinstance(sampler, str):
              if sampler == "synchronized":
                  kwargs[
                      "batch_sampler"
                  ] = TimeSynchronizedBatchSampler(
                      SequentialSampler(self),
                      batch_size=kwargs["batch_size"],
                      shuffle=kwargs["shuffle"],
                      drop_last=kwargs["drop_last"],
                  )
              else:
                  raise ValueError(
                      f"batch_sampler {sampler} unknown - see docstring for valid batch_sampler"
                  )
          del kwargs["batch_size"]
          del kwargs["shuffle"]
          del kwargs["drop_last"]
  
      return DataLoader(
          self,
          **kwargs,
      )
  
imports: from copy import copy, deepcopy
  from functools import lru_cache
  import inspect
  from typing import Any, Callable, Dict, List, Tuple, Union
  import warnings
  import matplotlib.pyplot
  import numpy
  import pandas
  from sklearn.exceptions import NotFittedError
  from sklearn.preprocessing import RobustScaler, StandardScaler
  from sklearn.utils.validation import check_is_fitted
  import torch
  from torch.distributions import Beta
  from torch.nn.utils import rnn
  from torch.utils.data import DataLoader, Dataset
  from torch.utils.data.sampler import Sampler, SequentialSampler
  from pytorch_forecasting.data.encoders import EncoderNormalizer, GroupNormalizer, MultiNormalizer, NaNLabelEncoder, TorchNormalizer
  from pytorch_forecasting.data.samplers import TimeSynchronizedBatchSampler
  from pytorch_forecasting.utils import repr_class
label_desc: Use image node_id 38 for calling the TimeSeriesDataSet obj's underlying member method code with example usage: obj.to_dataloader(train, batch_size, batch_sampler) and returns: DataLoader