code: def _inject_nans_in_target(
      data_entry: DataEntry, p: float
  ) -> DataEntry:
      """
      Returns a copy of the given `data_entry` where approximately `p` percent
      of the target values are NaNs.
  
      Parameters
      ----------
      data_entry
          The data entry to use as source.
      p
          The fraction of target positions to set to NaN (between 0 and 1).
  
      Returns
      -------
          A copy of `data_entry` with modified target field.
      """
      nan_positions = np.sort(
          a=np.random.choice(
              a=np.arange(data_entry["target"].size, dtype=int),
              size=int(p * data_entry["target"].size),
              replace=False,
          )
      )
  
      nan_target = np.copy(data_entry["target"])
      nan_target[nan_positions] = np.nan
  
      # if p < 1.0 at the last position should be kept unchanged
      # otherwise for large p we might end up with NaNs in the last
      # context_length positions
      if p < 1.0:
          nan_target[-1] = data_entry["target"][-1]
  
      return {
          key: (nan_target if key == "target" else val)
          for key, val in data_entry.items()
      }
  
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 6 for calling a global function with example usage: _inject_nans_in_target(data_entry, p) and returns: unknown