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: If dealing with classification, this utility encodes the targets.
  
  It does so by also using the classes from the test data, to prevent encoding
  errors
  
  Parameters
  ----------
      y_train: SUPPORTED_TARGET_TYPES
          The labels of the current task. They are going to be encoded in case
          of classification
      y_test: Optional[SUPPORTED_TARGET_TYPES]
          A holdout set of labels
docstr_tok: ["If","dealing","with","classification",",","this","utility","encodes","the","targets",".","It","does","so","by","also","using","the","classes","from","the","test","data",",","to","prevent","encoding","errors","Parameters","--","--","--","--","--","y_train",":","SUPPORTED_TARGET_TYPES","The","labels","of","the","current","task",".","They","are","going","to","be","encoded","in","case","of","classification","y_test",":","Optional","[","SUPPORTED_TARGET_TYPES","]","A","holdout","set","of","labels"]
code: def _fit(
      self,
      y_train: Union[List, np.ndarray, pd.Series, pd.DataFrame],
      y_test: Optional[
          Union[List, np.ndarray, pd.Series, pd.DataFrame]
      ] = None,
  ) -> "TargetValidator":
      """
      If dealing with classification, this utility encodes the targets.
  
      It does so by also using the classes from the test data, to prevent encoding
      errors
  
      Parameters
      ----------
          y_train: SUPPORTED_TARGET_TYPES
              The labels of the current task. They are going to be encoded in case
              of classification
          y_test: Optional[SUPPORTED_TARGET_TYPES]
              A holdout set of labels
      """
      if (
          not self.is_classification
          or self.type_of_target == "multilabel-indicator"
      ):
          # Only fit an encoder for classification tasks
          # Also, encoding multilabel indicator data makes the data multiclass
          # Let the user employ a MultiLabelBinarizer if needed
          self.encoder = None
          return self
  
      # Validate the shape of the input
      shape = np.shape(y_train)
      ndim = len(shape)
      if ndim > 1 and shape[1] != 1:
          # We should not reach this if statement, we check for type of targets before
          raise ValueError(
              "Multi-dimensional classification is not yet"
              " supported. Encoding multidimensional data"
              " converts multiple columns to a 1 dimensional encoding."
              f" Data involved = {shape}/{self.type_of_target}"
          )
  
      # Create the encoder
      self.encoder = OrdinalEncoder(handle_unknown="error")
  
      # Clear typing to just numpy arrays and pandas
      if isinstance(y_train, List):
          y = np.asarray(y_train)
      else:
          y = y_train
  
      # Attempt to store dtype if it's numeric, we use this in
      # inverse_transform to try corretly restore it's dtype
      if isinstance(y, pd.Series):
          if isinstance(y.dtype, ExtensionDtype):
              warnings.warn(
                  "Fitting transformer with a pandas series which"
                  f" has the dtype {y.dtype}. Inverse transform"
                  " may not be able preserve dtype when converting"
                  " to np.ndarray"
              )
          if is_numeric_dtype(y.dtype):
              self.dtype = y.dtype
      elif isinstance(y, pd.DataFrame):
          if is_numeric_dtype(y.dtypes[0]):
              self.dtype = y.dtypes[0]
      else:
          if is_numeric_dtype(y.dtype):
              self.dtype = y.dtype
  
      # Merge y_test and y_train for encoding
      if y_test is not None:
          if isinstance(y, (pd.Series, pd.DataFrame)):
              if isinstance(y, pd.Series):
                  y_test = pd.Series(y_test)
              else:
                  y_test = pd.DataFrame(y_test)
  
              y = pd.concat([y, y_test], ignore_index=True, sort=False)
          else:
              y = np.concatenate([y, y_test])
  
      # If one dimensional, we need to reshape it
      # [1, 2, 3] -> [[1], [2], [3]]
      if y.ndim == 1:
          if isinstance(y, pd.DataFrame) or isinstance(y, pd.Series):
              y = y.to_numpy()
  
          y = y.reshape(-1, 1)
  
      # Fit encoder
      self.encoder.fit(y)
  
      return self
  
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 3 for calling the TargetValidator obj's underlying member method code with example usage: obj._fit(y_train, y_test) and returns: self, self