code: def with_categorical_cols(
      data: pd.DataFrame, columns
  ) -> pd.DataFrame:
      """Convert selected columns of a DataFrame to categorical type.
  
      It converts all object columns plus columns specified in the `columns` argument.
      """
      # Convert 'object' and explicitly asked columns to categorical.
      object_columns = list(data.select_dtypes("object").columns)
      to_convert = list(set(object_columns + listify(columns)))
      if to_convert:
          data = data.copy()  # don't modify original data frame
          data[to_convert] = data[to_convert].apply(
              lambda x: x.astype("category")
          )
      return data
  
imports: import logging
  import warnings
  from copy import deepcopy
  from importlib.metadata import version
  import formulae
  import pymc
  import pandas
  from arviz.plots import plot_posterior
  from bambi.backend import PyMCModel
  from bambi.defaults import get_builtin_family
  from bambi.model_components import ConstantComponent, DistributionalComponent
  from bambi.families import Family, univariate
  from bambi.formula import Formula, check_ordinal_formula
  from bambi.priors import Prior, PriorScaler
  from bambi.transformations import transformations_namespace
  from bambi.utils import clean_formula_lhs, get_aliased_name, get_auxiliary_parameters, indentify, listify, remove_common_intercept, wrapify
label_desc: Use image node_id 1 for calling a global function with example usage: with_categorical_cols(data, columns) and returns: data