class_docstr: MatchCategories() ensures that categorical variables are encoded as pandas
  `'categorical'` dtype, instead of generic python `'object'` or other dtypes.
  
  Under the hood, `'categorical'` dtype is a representation that maps each
  category to an integer, thus providing a more memory-efficient object
  structure than, e.g., 'str', and allowing faster grouping, mapping, and similar
  operations on the resulting object.
  
  MatchCategories() remembers the encodings or levels that represent each
  category, and can thus can be used to ensure that the correct encoding gets
  applied when passing categorical data to modeling packages that support this
  dtype, or to prevent unseen categories from reaching a further transformer
  or estimator in a pipeline, for example.
  
  More details in the :ref:`User Guide <match_categories>`.
  
  Parameters
  ----------
  {variables}
  
  {ignore_format}
  
  {missing_values}
  
  Attributes
  ----------
  category_dict_:
      Dictionary with the category encodings assigned to each variable.
  
  {variables_}
  
  {feature_names_in_}
  
  {n_features_in_}
  
  Methods
  -------
  fit:
      Learn the encodings or levels to use for each variable.
  
  fit_transform:
      Fit to the data. Then transform it.
  
  get_feature_names_out:
      Get output feature names for transformation.
  
  get_params:
      Get parameters for this estimator.
  
  set_params:
      Set the parameters of this estimator.
  
  transform:
      Enforce the type of categorical variables as dtype `categorical`.
class_docstr_tok: ["MatchCategories","(",")","ensures","that","categorical","variables","are","encoded","as","pandas","`","'categorical","'","`","dtype",",","instead","of","generic","python","`","'object","'","`","or","other","dtypes",".","Under","the","hood",",","`","'categorical","'","`","dtype","is","a","representation","that","maps","each","category","to","an","integer",",","thus","providing","a","more","memory-efficient","object","structure","than",",","e.g.",",","'str","'",",","and","allowing","faster","grouping",",","mapping",",","and","similar","operations","on","the","resulting","object",".","MatchCategories","(",")","remembers","the","encodings","or","levels","that","represent","each","category",",","and","can","thus","can","be","used","to","ensure","that","the","correct","encoding","gets","applied","when","passing","categorical","data","to","modeling","packages","that","support","this","dtype",",","or","to","prevent","unseen","categories","from","reaching","a","further","transformer","or","estimator","in","a","pipeline",",","for","example",".","More","details","in","the",":","ref",":","`","User","Guide","<","match_categories",">","`",".","Parameters","--","--","--","--","--","{","variables","}","{","ignore_format","}","{","missing_values","}","Attributes","--","--","--","--","--","category_dict_",":","Dictionary","with","the","category","encodings","assigned","to","each","variable",".","{","variables_","}","{","feature_names_in_","}","{","n_features_in_","}","Methods","--","--","--","-","fit",":","Learn","the","encodings","or","levels","to","use","for","each","variable",".","fit_transform",":","Fit","to","the","data",".","Then","transform","it",".","get_feature_names_out",":","Get","output","feature","names","for","transformation",".","get_params",":","Get","parameters","for","this","estimator",".","set_params",":","Set","the","parameters","of","this","estimator",".","transform",":","Enforce","the","type","of","categorical","variables","as","dtype","`","categorical","`","."]
docstr: Encode categorical variables as pandas categorical dtype.
  
  Parameters
  ----------
  X: pandas dataframe of shape = [n_samples, n_features].
      The dataset to encode.
  
  Returns
  -------
  X_new: pandas dataframe of shape = [n_samples, n_features].
      The dataframe with the variables encoded as pandas categorical dtype.
docstr_tok: ["Encode","categorical","variables","as","pandas","categorical","dtype",".","Parameters","--","--","--","--","--","X",":","pandas","dataframe","of","shape","=","[","n_samples",",","n_features","]",".","The","dataset","to","encode",".","Returns","--","--","--","-","X_new",":","pandas","dataframe","of","shape","=","[","n_samples",",","n_features","]",".","The","dataframe","with","the","variables","encoded","as","pandas","categorical","dtype","."]
code: def transform(self, X: pd.DataFrame) -> pd.DataFrame:
      """
      Encode categorical variables as pandas categorical dtype.
  
      Parameters
      ----------
      X: pandas dataframe of shape = [n_samples, n_features].
          The dataset to encode.
  
      Returns
      -------
      X_new: pandas dataframe of shape = [n_samples, n_features].
          The dataframe with the variables encoded as pandas categorical dtype.
      """
      X = self._check_transform_input_and_state(X)
  
      if self.missing_values == "raise":
          _check_contains_na(X, self.variables_)
  
      for feature, levels in self.category_dict_.items():
          X[feature] = pd.Categorical(X[feature], levels)
  
      self._check_nas_in_result(X)
      return X
  
file_path: feature_engine/feature_engine/preprocessing/match_categories.py
imports: import warnings
  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.init_parameters import _ignore_format_docstring, _missing_values_docstring, _variables_categorical_docstring
  from feature_engine._docstrings.substitute import Substitution
  from feature_engine.dataframe_checks import _check_contains_na, check_X
  from feature_engine.encoding.base_encoder import CategoricalInitMixin, CategoricalMethodsMixin
  from feature_engine._base_transformers.mixins import GetFeatureNamesOutMixin
label_desc: Use image node_id 3 for calling the MatchCategories obj's underlying member method code with example usage: obj.transform(X) and returns: X