code: def _test_nans_in_target(
      predictor: NPTSPredictor, dataset: Dataset
  ) -> None:
      """
      Test that the model behaves as expected when the target time series
      contains NaN values.
  
      Parameters
      ----------
      predictor
          the predictor instance to test
      dataset
          a dataset (with targets without NaNs) to use as a base for the test
      """
  
      # a copy of dataset with 90% of the target entries NaNs
      ds_090pct_nans = [
          _inject_nans_in_target(data_entry, p=0.9)
          for data_entry in dataset
      ]
  
      # a copy of dataset with 100% of the target entries NaNs
      ds_100pct_nans = [
          _inject_nans_in_target(data_entry, p=1.0)
          for data_entry in dataset
      ]
  
      # assert that we can tolerate a high percentage of NaNs
      for forecast in predictor.predict(ds_090pct_nans):
          assert np.all(
              np.isfinite(forecast.samples)
          ), "Forecast contains NaNs."
  
      # assert that an exception is thrown if 100% of the values are NaN
      with pytest.raises(GluonTSDataError) as excinfo:
          for _ in predictor.predict(ds_100pct_nans):
              pass
      assert (
          f"The last {predictor.context_length} positions of the target time "
          f"series are all NaN. Please increase the `context_length` "
          f"parameter of your NPTS model so the last "
          f"{predictor.context_length} positions of each target contain at "
          f"least one non-NaN value."
      ) in str(excinfo.value)
  
file_path: gluonts/test/model/npts/test_npts.py
imports: from typing import Optional
  import numpy
  import pandas
  import pytest
  from gluonts.dataset.common import DataEntry, Dataset
  from gluonts.exceptions import GluonTSDataError
  from gluonts.model.npts import KernelType, NPTSPredictor
  from gluonts.model.npts._weighted_sampler import WeightedSampler
label_desc: Use image node_id 5 for calling a global function with example usage: _test_nans_in_target(predictor, dataset) without return types