code: def check_y(y, enforce_min_instances=1, coerce_to_numpy=False):
      """Validate input data.
  
      Parameters
      ----------
      y : pd.Series or np.array
      enforce_min_instances : int, optional (default=1)
          Enforce minimum number of instances.
      coerce_to_numpy : bool, optional (default=False)
          If True, y will be coerced to a numpy array.
  
      Returns
      -------
      y : pd.Series or np.array
      Raises
      ------
      ValueError
          If y is an invalid input
      """
      if not isinstance(y, VALID_Y_TYPES):
          raise ValueError(
              f"y must be either a pd.Series or a np.ndarray, "
              f"but found type: {type(y)}"
          )
  
      if enforce_min_instances > 0:
          _enforce_min_instances(y, min_instances=enforce_min_instances)
  
      if coerce_to_numpy and isinstance(y, pd.Series):
          y = y.to_numpy()
  
      return y
  
file_path: sktime/sktime/utils/validation/panel.py
imports: import numpy
  import pandas
  from sklearn.utils.validation import check_consistent_length
  from sktime.datatypes._panel._check import is_nested_dataframe
  from sktime.datatypes._panel._convert import from_3d_numpy_to_nested, from_nested_to_3d_numpy
label_desc: Use image node_id 2 for calling a global function with example usage: check_y(y, enforce_min_instances, coerce_to_numpy) and returns: y