code: def _find_or_check_categorical_variables(
      X: pd.DataFrame, variables: Variables = None
  ) -> List[Union[str, int]]:
      """
      Checks that variables provided by the user are of type object or categorical.
      If None, finds all the categorical and object type variables in the DataFrame.
  
      Parameters
      ----------
      X : pandas DataFrame.
      variables : variable or list of variables. Defaults to None.
  
      Raises
      ------
      ValueError
          If there are no categorical variables in df or df is empty.
      TypeError
          If any of the user provided variables are not categorical.
  
      Returns
      -------
      variables : List of categorical variables.
      """
  
      if variables is None:
          # find categorical variables in dataset
          variables = [
              column
              for column in X.select_dtypes(
                  include=["O", "category"]
              ).columns
              if _is_categorical_and_is_not_datetime(X[column])
          ]
          if len(variables) == 0:
              raise ValueError(
                  "No categorical variables found in this dataframe. Please check "
                  "variable format with pandas dtypes."
              )
  
      elif isinstance(variables, (str, int)):
          if is_categorical(X[variables]) or is_object(X[variables]):
              variables = [variables]
          else:
              raise TypeError(
                  "The variable entered is not categorical."
              )
  
      else:
          if len(variables) == 0:
              raise ValueError("The list of variables is empty.")
  
          # check that user entered variables are of type categorical
          else:
              if (
                  len(
                      X[variables]
                      .select_dtypes(exclude=["O", "category"])
                      .columns
                  )
                  > 0
              ):
                  raise TypeError(
                      "Some of the variables are not categorical. Please cast them as "
                      "categorical or object before using this transformer."
                  )
  
      return variables
  
file_path: feature_engine/feature_engine/_variable_handling/variable_type_selection.py
imports: from typing import List, Tuple, Union
  import pandas
  from pandas.api.types import is_categorical_dtype
  from pandas.api.types import is_datetime64_any_dtype
  from pandas.api.types import is_numeric_dtype
  from pandas.api.types import is_object_dtype
  from feature_engine._variable_handling.variable_type_checks import _is_categorical_and_is_datetime, _is_categorical_and_is_not_datetime
label_desc: Use image node_id 2 for calling a global function with example usage: _find_or_check_categorical_variables(X, variables) and returns: variables