code: def _computations_as_categorical(
      df: pd.DataFrame, **kwargs
  ) -> pd.DataFrame:
      """
      This function handles cases where
      categorical columns are created with an order,
      or specific values supplied for the categories.
      It uses a kwarg, where the key is the column name,
      and the value is either a string, or a 1D array.
      The default for value is None and will return a categorical dtype
      with no order and categories inferred from the column.
      A DataFrame, with categorical columns, is returned.
      """
  
      categories_dict = _as_categorical_checks(df, **kwargs)
  
      categories_dtypes = {}
  
      for column_name, value in categories_dict.items():
          if value is None:
              cat_dtype = pd.CategoricalDtype()
          elif isinstance(value, str):
              if value == _CategoryOrder.SORT.value:
                  _, cat_dtype = df[column_name].factorize(sort=True)
              else:
                  _, cat_dtype = df[column_name].factorize(sort=False)
              if cat_dtype.empty:
                  raise ValueError(
                      "Kindly ensure there is at least "
                      f"one non-null value in {column_name}."
                  )
              cat_dtype = pd.CategoricalDtype(
                  categories=cat_dtype, ordered=True
              )
  
          else:  # 1-D array
              cat_dtype = pd.CategoricalDtype(
                  categories=value, ordered=True
              )
  
          categories_dtypes[column_name] = cat_dtype
  
      return df.astype(categories_dtypes)
  
file_path: pyjanitor/janitor/functions/encode_categorical.py
imports: import warnings
  from enum import Enum
  from typing import Any, Hashable, Iterable, Union
  import numpy
  import pandas
  import pandas_flavor
  from pandas.api.types import is_list_like
  from janitor.functions.utils import get_index_labels
  from janitor.utils import check_column, deprecated_alias, find_stack_level
label_desc: Use image node_id 2 for calling a global function with example usage: _computations_as_categorical(df) and returns: df