check_for_nonfinite#

pytorch_forecasting.data.timeseries._timeseries.check_for_nonfinite(tensor: Tensor, names: str | list[str]) Tensor[source]#

Check if tensor contains NAs or infinite values and has correct dimension.

Checks:

  • whether tensor is finite, otherwise raises ValueError

  • checks whether dimension of tensor is correct. If tensor is a str, tensor.ndim has to be 1, and if tensor is a list, tensor.ndim has to be 2. Otherwise raises AssertionError.

Parameters:
  • names (str or list of str) – name(s) of column(s) to check

  • tensor (torch.Tensor) – tensor to check

Returns:

returns tensor unchanged, if checks yield no issues

Return type:

torch.Tensor

Raises:
  • ValueError – if tensor contains NAs or infinite values

  • AssertionError – if tensor has incorrect dimension, see above