code: def encode_categorical(table, columns=None, **kwargs):
      """
      Encode categorical columns with `M` categories into `M-1` columns according
      to the one-hot scheme.
  
      Parameters
      ----------
      table : pandas.DataFrame
          Table with categorical columns to encode.
  
      columns : list-like, optional, default: None
          Column names in the DataFrame to be encoded.
          If `columns` is None then all the columns with
          `object` or `category` dtype will be converted.
  
      allow_drop : boolean, optional, default: True
          Whether to allow dropping categorical columns that only consist
          of a single category.
  
      Returns
      -------
      encoded : pandas.DataFrame
          Table with categorical columns encoded as numeric.
          Numeric columns in the input table remain unchanged.
      """
      if isinstance(table, pd.Series):
          if not isinstance(
              table.dtype, CategoricalDtype
          ) and not is_object_dtype(table.dtype):
              raise TypeError(
                  f"series must be of categorical dtype, but was {table.dtype}"
              )
          return _encode_categorical_series(table, **kwargs)
  
      def _is_categorical_or_object(series):
          return isinstance(
              series.dtype, CategoricalDtype
          ) or is_object_dtype(series.dtype)
  
      if columns is None:
          # for columns containing categories
          columns_to_encode = {
              nam
              for nam, s in table.items()
              if _is_categorical_or_object(s)
          }
      else:
          columns_to_encode = set(columns)
  
      items = []
      for name, series in table.items():
          if name in columns_to_encode:
              series = _encode_categorical_series(series, **kwargs)
              if series is None:
                  continue
          items.append(series)
  
      # concat columns of tables
      new_table = pd.concat(items, axis=1, copy=False)
      return new_table
  
file_path: scikit-survival/sksurv/column.py
imports: import logging
  import numpy
  import pandas
  from pandas.api.types import CategoricalDtype, is_object_dtype
label_desc: Use image node_id 5 for calling a global function with example usage: encode_categorical(table, columns) and returns: new_table, _encode_categorical_series, unknown