original_docstring: 
      Format a Table depending on the key that was used and a Formatter object.
  
      Args:
          table (``datasets.table.Table``): The input Table to format
          key (``Union[int, slice, range, str, Iterable]``): Depending on the key that was used, the formatter formats
              the table as either a row, a column or a batch.
          formatter (``datasets.formatting.formatting.Formatter``): Any subclass of a Formatter such as
              PythonFormatter, NumpyFormatter, etc.
          format_columns (Optional ``List[str]``): if not None, it defines the columns that will be formatted using the
              given formatter. Other columns are discarded (unless ``output_all_columns`` is True)
          output_all_columns (``bool``, defaults to False). If True, the formatted output is completed using the columns
              that are not in the ``format_columns`` list. For these columns, the PythonFormatter is used.
  
  
      Returns:
          A row, column or batch formatted object defined by the Formatter:
          - the PythonFormatter returns a dictionary for a row or a batch, and a list for a column.
          - the NumpyFormatter returns a dictionary for a row or a batch, and a np.array for a column.
          - the PandasFormatter returns a pd.DataFrame for a row or a batch, and a pd.Series for a column.
          - the TorchFormatter returns a dictionary for a row or a batch, and a torch.Tensor for a column.
          - the TFFormatter returns a dictionary for a row or a batch, and a tf.Tensor for a column.
      
docstring: Format a Table depending on the key that was used and a Formatter object.
  
  A row, column or batch formatted object defined by the Formatter:
  the PythonFormatter returns a dictionary for a row or a batch, and a list for a column.
  the NumpyFormatter returns a dictionary for a row or a batch, and a np.array for a column.
  the PandasFormatter returns a pd.DataFrame for a row or a batch, and a pd.Series for a column.
  the TorchFormatter returns a dictionary for a row or a batch, and a torch.Tensor for a column.
  the TFFormatter returns a dictionary for a row or a batch, and a tf.Tensor for a column.
docstring_tokens: Format a Table depending on the key that was used and a Formatter object . A row column or batch formatted object defined by the Formatter : the PythonFormatter returns a dictionary for a row or a batch and a list for a column . the NumpyFormatter returns a dictionary for a row or a batch and a np . array for a column . the PandasFormatter returns a pd . DataFrame for a row or a batch and a pd . Series for a column . the TorchFormatter returns a dictionary for a row or a batch and a torch . Tensor for a column . the TFFormatter returns a dictionary for a row or a batch and a tf . Tensor for a column .
code: def format_table(
      table: Table,
      key: Union[int, slice, range, str, Iterable],
      formatter: Formatter,
      format_columns: Optional[list] = None,
      output_all_columns=False,
  ):
      """
      Format a Table depending on the key that was used and a Formatter object.
  
      Args:
          table (``datasets.table.Table``): The input Table to format
          key (``Union[int, slice, range, str, Iterable]``): Depending on the key that was used, the formatter formats
              the table as either a row, a column or a batch.
          formatter (``datasets.formatting.formatting.Formatter``): Any subclass of a Formatter such as
              PythonFormatter, NumpyFormatter, etc.
          format_columns (Optional ``List[str]``): if not None, it defines the columns that will be formatted using the
              given formatter. Other columns are discarded (unless ``output_all_columns`` is True)
          output_all_columns (``bool``, defaults to False). If True, the formatted output is completed using the columns
              that are not in the ``format_columns`` list. For these columns, the PythonFormatter is used.
  
  
      Returns:
          A row, column or batch formatted object defined by the Formatter:
          - the PythonFormatter returns a dictionary for a row or a batch, and a list for a column.
          - the NumpyFormatter returns a dictionary for a row or a batch, and a np.array for a column.
          - the PandasFormatter returns a pd.DataFrame for a row or a batch, and a pd.Series for a column.
          - the TorchFormatter returns a dictionary for a row or a batch, and a torch.Tensor for a column.
          - the TFFormatter returns a dictionary for a row or a batch, and a tf.Tensor for a column.
      """
      if isinstance(table, Table):
          pa_table = table.table
      else:
          pa_table = table
      query_type = key_to_query_type(key)
      python_formatter = PythonFormatter(features=None)
      if format_columns is None:
          return formatter(pa_table, query_type=query_type)
      elif query_type == "column":
          if key in format_columns:
              return formatter(pa_table, query_type)
          else:
              return python_formatter(pa_table, query_type=query_type)
      else:
          pa_table_to_format = pa_table.drop(col for col in pa_table.column_names if col not in format_columns)
          formatted_output = formatter(pa_table_to_format, query_type=query_type)
          if output_all_columns:
              if isinstance(formatted_output, MutableMapping):
                  pa_table_with_remaining_columns = pa_table.drop(
                      col for col in pa_table.column_names if col in format_columns
                  )
                  remaining_columns_dict = python_formatter(pa_table_with_remaining_columns, query_type=query_type)
                  formatted_output.update(remaining_columns_dict)
              else:
                  raise TypeError(
                      f"Custom formatting function must return a dict to work with output_all_columns=True, but got {formatted_output}"
                  )
          return formatted_output
code_tokens: def format_table ( table : Table , key : Union [ int , slice , range , str , Iterable ] , formatter : Formatter , format_columns : Optional [ list ] = None , output_all_columns = False , ) : if isinstance ( table , Table ) : pa_table = table . table else : pa_table = table query_type = key_to_query_type ( key ) python_formatter = PythonFormatter ( features = None ) if format_columns is None : return formatter ( pa_table , query_type = query_type ) elif query_type == "column" : if key in format_columns : return formatter ( pa_table , query_type ) else : return python_formatter ( pa_table , query_type = query_type ) else : pa_table_to_format = pa_table . drop ( col for col in pa_table . column_names if col not in format_columns ) formatted_output = formatter ( pa_table_to_format , query_type = query_type ) if output_all_columns : if isinstance ( formatted_output , MutableMapping ) : pa_table_with_remaining_columns = pa_table . drop ( col for col in pa_table . column_names if col in format_columns ) remaining_columns_dict = python_formatter ( pa_table_with_remaining_columns , query_type = query_type ) formatted_output . update ( remaining_columns_dict ) else : raise TypeError ( f"Custom formatting function must return a dict to work with output_all_columns=True, but got {formatted_output}" ) return formatted_output
short_docstring: Format a Table depending on the key that was used and a Formatter object.
short_docstring_tokens: Format a Table depending on the key that was used and a Formatter object .
comment: """
      Format a Table depending on the key that was used and a Formatter object.
  
      Args:
          table (``datasets.table.Table``): The input Table to format
          key (``Union[int, slice, range, str, Iterable]``): Depending on the key that was used, the formatter formats
              the table as either a row, a column or a batch.
          formatter (``datasets.formatting.formatting.Formatter``): Any subclass of a Formatter such as
              PythonFormatter, NumpyFormatter, etc.
          format_columns (Optional ``List[str]``): if not None, it defines the columns that will be formatted using the
              given formatter. Other columns are discarded (unless ``output_all_columns`` is True)
          output_all_columns (``bool``, defaults to False). If True, the formatted output is completed using the columns
              that are not in the ``format_columns`` list. For these columns, the PythonFormatter is used.
  
  
      Returns:
          A row, column or batch formatted object defined by the Formatter:
          - the PythonFormatter returns a dictionary for a row or a batch, and a list for a column.
          - the NumpyFormatter returns a dictionary for a row or a batch, and a np.array for a column.
          - the PandasFormatter returns a pd.DataFrame for a row or a batch, and a pd.Series for a column.
          - the TorchFormatter returns a dictionary for a row or a batch, and a torch.Tensor for a column.
          - the TFFormatter returns a dictionary for a row or a batch, and a tf.Tensor for a column.
      """