parameters: (arr)
return_statement: return arr
docstring: Ensure that an array-like object is a Categorical (if not already).
  
      Parameters
      ----------
      arr : array-like
          The array that we want to convert into a Categorical.
  
      Returns
      -------
      cat_arr : The original array cast as a Categorical. If it already
                is a Categorical, we return as is.
docstring_summary: Ensure that an array-like object is a Categorical (if not already).
docstring_tokens: Ensure that an array - like object is a Categorical ( if not already ) .
function: def ensure_categorical(arr):
      """
      Ensure that an array-like object is a Categorical (if not already).
  
      Parameters
      ----------
      arr : array-like
          The array that we want to convert into a Categorical.
  
      Returns
      -------
      cat_arr : The original array cast as a Categorical. If it already
                is a Categorical, we return as is.
      """
  
      if not is_categorical(arr):
          from pandas import Categorical
  
          arr = Categorical(arr)
      return arr
function_tokens: def ensure_categorical ( arr ) : if not is_categorical ( arr ) : from pandas import Categorical arr = Categorical ( arr ) return arr