class_docstr: The CategoricalImputer() replaces missing data in categorical variables by an
  arbitrary value or by the most frequent category.
  
  The CategoricalImputer() imputes by default only categorical variables
  (type 'object' or 'categorical'). You can pass a list of variables to impute, or
  alternatively, the encoder will find and impute all categorical variables.
  
  If you want to impute numerical variables with this transformer, there are 2 ways
  of doing it:
  
  **Option 1**: Cast your numerical variables as object in the input dataframe before
  passing it to the transformer.
  
  **Option 2**: Set `ignore_format=True`. Note that if you do this and do not pass the
  list of variables to impute, the imputer will automatically select and impute all
  variables in the dataframe.
  
  More details in the :ref:`User Guide <categorical_imputer>`.
  
  Parameters
  ----------
  imputation_method: str, default='missing'
      Desired method of imputation. Can be 'frequent' for frequent category imputation
      or 'missing' to impute with an arbitrary value.
  
  fill_value: str, int, float, default='Missing'
      User-defined value to replace missing data. Only used when
      `imputation_method='missing'`.
  
  variables: list, default=None
      The list of categorical variables that will be imputed. If None, the
      imputer will find and transform all variables of type object or categorical by
      default. You can also make the transformer accept numerical variables, see the
      parameter `ignore_format` below.
  
  return_object: bool, default=False
      If working with numerical variables cast as object, decide
      whether to return the variables as numeric or re-cast them as object.
      Note that pandas will re-cast them automatically as numeric after the
      transformation with the mode or with an arbitrary number.
  
  ignore_format: bool, default=False
      Whether the format in which the categorical variables are cast should be
      ignored. If false, the imputer will automatically select variables of type
      object or categorical, or check that the variables entered by the user are of
      type object or categorical. If True, the imputer will select all variables or
      accept all variables entered by the user, including those cast as numeric.
  
  Attributes
  ----------
  {imputer_dict_}
  
  {variables_}
  
  {feature_names_in_}
  
  {n_features_in_}
  
  Methods
  -------
  fit:
      Learn the most frequent category or assign arbitrary value to variable.
  
  {fit_transform}
  
  {transform}
  
  Examples
  --------
  
  >>> import pandas as pd
  >>> import numpy as np
  >>> from feature_engine.imputation import CategoricalImputer
  >>> X = pd.DataFrame(dict(
  >>>        x1 = [np.nan,1,1,0,np.nan],
  >>>        x2 = ["a", np.nan, "b", np.nan, "a"],
  >>>        ))
  >>> ci = CategoricalImputer(imputation_method='frequent')
  >>> ci.fit(X)
  >>> ci.transform(X)
      x1 x2
  0  NaN  a
  1  1.0  a
  2  1.0  b
  3  0.0  a
  4  NaN  a
code: def __init__(
      self,
      imputation_method: str = "missing",
      fill_value: Union[str, int, float] = "Missing",
      variables: Union[None, int, str, List[Union[str, int]]] = None,
      return_object: bool = False,
      ignore_format: bool = False,
  ) -> None:
      if imputation_method not in ["missing", "frequent"]:
          raise ValueError(
              "imputation_method takes only values 'missing' or 'frequent'"
          )
  
      if not isinstance(ignore_format, bool):
          raise ValueError(
              "ignore_format takes only booleans True and False"
          )
  
      self.imputation_method = imputation_method
      self.fill_value = fill_value
      self.variables = _check_init_parameter_variables(variables)
      self.return_object = return_object
      self.ignore_format = ignore_format
  
file_path: feature_engine/feature_engine/imputation/categorical.py
imports: from typing import List, Optional, Union
  import pandas
  from feature_engine._docstrings.fit_attributes import _feature_names_in_docstring, _n_features_in_docstring, _variables_attribute_docstring
  from feature_engine._docstrings.methods import _fit_transform_docstring
  from feature_engine._docstrings.substitute import Substitution
  from feature_engine._variable_handling.init_parameter_checks import _check_init_parameter_variables
  from feature_engine._variable_handling.variable_type_selection import _find_all_variables, _find_or_check_categorical_variables
  from feature_engine.dataframe_checks import check_X
  from feature_engine.imputation.base_imputer import BaseImputer
  from feature_engine.tags import _return_tags
label_desc: Use image node_id 1 to create a new CategoricalImputer object from inherited base classes: BaseImputer with example: obj = CategoricalImputer(imputation_method, fill_value, variables, return_object, ignore_format)