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 targets
  The supported data types are List, numpy arrays and pandas DataFrames.
  
  Parameters
  ----------
      y_train: SUPPORTED_TARGET_TYPES
          A set of targets set aside for training
      y_test: Union[SUPPORTED_TARGET_TYPES]
          A hold out set of data used of the targets. It is also used to fit the
          categories of the encoder.
docstr_tok: ["Validates","and","fit","a","categorical","encoder","(","if","needed",")","to","the","targets","The","supported","data","types","are","List",",","numpy","arrays","and","pandas","DataFrames",".","Parameters","--","--","--","--","--","y_train",":","SUPPORTED_TARGET_TYPES","A","set","of","targets","set","aside","for","training","y_test",":","Union","[","SUPPORTED_TARGET_TYPES","]","A","hold","out","set","of","data","used","of","the","targets",".","It","is","also","used","to","fit","the","categories","of","the","encoder","."]
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":
      """
      Validates and fit a categorical encoder (if needed) to the targets
      The supported data types are List, numpy arrays and pandas DataFrames.
  
      Parameters
      ----------
          y_train: SUPPORTED_TARGET_TYPES
              A set of targets set aside for training
          y_test: Union[SUPPORTED_TARGET_TYPES]
              A hold out set of data used of the targets. It is also used to fit the
              categories of the encoder.
      """
      # Check that the data is valid
      self._check_data(y_train)
  
      shape = np.shape(y_train)
      if y_test is not None:
          self._check_data(y_test)
  
          if len(shape) != len(np.shape(y_test)) or (
              len(shape) > 1 and (shape[1] != np.shape(y_test)[1])
          ):
              raise ValueError(
                  "The dimensionality of the train and test"
                  " targets do not match"
                  f" train {np.shape(y_train)}"
                  f" != test {np.shape(y_test)}"
              )
  
          if isinstance(y_train, pd.DataFrame):
              if not isinstance(y_test, pd.DataFrame):
                  y_test = pd.DataFrame(y_test)
  
              if y_train.columns.tolist() != y_test.columns.tolist():
                  raise ValueError(
                      "Train and test targets must both have the"
                      f" same columns, yet y={y_train.columns}"
                      f" and y_test={y_test.columns}"
                  )
  
              if list(y_train.dtypes) != list(y_test.dtypes):
                  raise ValueError(
                      "Train and test targets must both have the same dtypes"
                  )
  
      if self.out_dimensionality is None:
          self.out_dimensionality = 1 if len(shape) == 1 else shape[1]
      else:
          _n_outputs = 1 if len(shape) == 1 else shape[1]
          if self.out_dimensionality != _n_outputs:
              raise ValueError(
                  "Number of outputs changed from %d to %d!"
                  % (self.out_dimensionality, _n_outputs)
              )
  
      # Fit on the training data
      self._fit(y_train, y_test)
  
      self._is_fitted = True
  
      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 2 for calling the TargetValidator obj's underlying member method code with example usage: obj.fit(y_train, y_test) and returns: self