class_docstr: A class to pre-process targets.
  
  It validates the data provided during fit to make sure it matches Sklearn
  expectation as well as encoding the targets in case of classification
  
  Attributes
  ----------
  is_classification: bool
      A bool that indicates if the validator should operate in classification mode.
      During classification, the targets are encoded.
  
  encoder: Optional[BaseEstimator]
      Host a encoder object if the data requires transformation (for example, if
      provided a categorical column in a pandas DataFrame).
  
  enc_columns: List[str]
      List of columns that where encoded
class_docstr_tok: ["A","class","to","pre-process","targets",".","It","validates","the","data","provided","during","fit","to","make","sure","it","matches","Sklearn","expectation","as","well","as","encoding","the","targets","in","case","of","classification","Attributes","--","--","--","--","--","is_classification",":","bool","A","bool","that","indicates","if","the","validator","should","operate","in","classification","mode",".","During","classification",",","the","targets","are","encoded",".","encoder",":","Optional","[","BaseEstimator","]","Host","a","encoder","object","if","the","data","requires","transformation","(","for","example",",","if","provided","a","categorical","column","in","a","pandas","DataFrame",")",".","enc_columns",":","List","[","str","]","List","of","columns","that","where","encoded"]
docstr: Validates and fit a categorical encoder (if needed) to the features.
  The supported data types are List, numpy arrays and pandas DataFrames.
  
  Parameters
  ----------
      y: SUPPORTED_TARGET_TYPES
          A set of targets that are going to be encoded if the current task
          is classification
  Return
  ------
      np.ndarray:
          The transformed array
docstr_tok: ["Validates","and","fit","a","categorical","encoder","(","if","needed",")","to","the","features",".","The","supported","data","types","are","List",",","numpy","arrays","and","pandas","DataFrames",".","Parameters","--","--","--","--","--","y",":","SUPPORTED_TARGET_TYPES","A","set","of","targets","that","are","going","to","be","encoded","if","the","current","task","is","classification","Return","--","--","--","np.ndarray",":","The","transformed","array"]
code: def transform(
      self,
      y: Union[List, pd.Series, pd.DataFrame, np.ndarray],
  ) -> np.ndarray:
      """
      Validates and fit a categorical encoder (if needed) to the features.
      The supported data types are List, numpy arrays and pandas DataFrames.
  
      Parameters
      ----------
          y: SUPPORTED_TARGET_TYPES
              A set of targets that are going to be encoded if the current task
              is classification
      Return
      ------
          np.ndarray:
              The transformed array
      """
      if not self._is_fitted:
          raise NotFittedError(
              "TargetValidator must have fit() called first"
          )
  
      # Check the data here so we catch problems on new test data
      self._check_data(y)
  
      # Clear the types List and DataFrame off of y
      if isinstance(y, List):
          y_transformed = np.asarray(y)
      elif isinstance(y, pd.DataFrame) or isinstance(y, pd.Series):
          y_transformed = y.to_numpy()
      else:
          y_transformed = y
  
      if self.encoder is None:
          return y_transformed
  
      # The Ordinal encoder expects a 2 dimensional input.
      # The targets are 1 dimensional, so reshape to match the expected shape
      if y_transformed.ndim == 1:
          y_transformed = y_transformed.reshape(-1, 1)
          y_transformed = self.encoder.transform(y_transformed).reshape(
              -1
          )
      else:
          y_transformed = self.encoder.transform(y_transformed)
  
      # check_array ensures correct numerical features for array
      y_transformed = sklearn.utils.check_array(
          y_transformed,
          force_all_finite=True,
          accept_sparse="csr",
          ensure_2d=False,
      )
  
      # Ensure we flatten any arrays [[1], [2], [1], [1], ...] to [1,2,1,1,...]
      if y_transformed.ndim == 2 and y_transformed.shape[1] == 1:
          y_transformed = y_transformed.ravel()
  
      return y_transformed
  
imports: from typing import List, Optional, Type, Union, cast
  import logging
  import warnings
  import numpy
  import pandas
  import sklearn.utils
  from pandas.api.types import is_numeric_dtype
  from pandas.core.dtypes.base import ExtensionDtype
  from scipy.sparse import spmatrix
  from sklearn.base import BaseEstimator
  from sklearn.exceptions import NotFittedError
  from sklearn.preprocessing import OrdinalEncoder
  from sklearn.utils.multiclass import type_of_target
  from autosklearn.util.logging_ import PickableLoggerAdapter
label_desc: Use image node_id 4 for calling the TargetValidator obj's underlying member method code with example usage: obj.transform(y) and returns: y_transformed, y_transformed