class_docstr: Matchzoo :class:`DataPack` data structure, store dataframe and context.
  
  `DataPack` is a MatchZoo native data structure that most MatchZoo data
  handling processes build upon. A `DataPack` consists of three parts:
  `left`, `right` and `relation`, each one of is a `pandas.DataFrame`.
  
  :param relation: Store the relation between left document
      and right document use ids.
  :param left: Store the content or features for id_left.
  :param right: Store the content or features for
      id_right.
  
  Example:
      >>> left = [
      ...     ['qid1', 'query 1'],
      ...     ['qid2', 'query 2']
      ... ]
      >>> right = [
      ...     ['did1', 'document 1'],
      ...     ['did2', 'document 2']
      ... ]
      >>> relation = [['qid1', 'did1', 1], ['qid2', 'did2', 1]]
      >>> relation_df = pd.DataFrame(relation)
      >>> left = pd.DataFrame(left)
      >>> right = pd.DataFrame(right)
      >>> dp = DataPack(
      ...     relation=relation_df,
      ...     left=left,
      ...     right=right,
      ... )
      >>> len(dp)
      2
class_docstr_tok: ["Matchzoo",":","class",":","`","DataPack","`","data","structure",",","store","dataframe","and","context",".","`","DataPack","`","is","a","MatchZoo","native","data","structure","that","most","MatchZoo","data","handling","processes","build","upon",".","A","`","DataPack","`","consists","of","three","parts",":","`","left","`",",","`","right","`","and","`","relation","`",",","each","one","of","is","a","`","pandas.DataFrame","`",".",":","param","relation",":","Store","the","relation","between","left","document","and","right","document","use","ids",".",":","param","left",":","Store","the","content","or","features","for","id_left",".",":","param","right",":","Store","the","content","or","features","for","id_right",".","Example",":",">",">",">","left","=","[","...","[","'qid1","'",",","'query","1","'","]",",","...","[","'qid2","'",",","'query","2","'","]","...","]",">",">",">","right","=","[","...","[","'did1","'",",","'document","1","'","]",",","...","[","'did2","'",",","'document","2","'","]","...","]",">",">",">","relation","=","[","[","'qid1","'",",","'did1","'",",","1","]",",","[","'qid2","'",",","'did2","'",",","1","]","]",">",">",">","relation_df","=","pd.DataFrame","(","relation",")",">",">",">","left","=","pd.DataFrame","(","left",")",">",">",">","right","=","pd.DataFrame","(","right",")",">",">",">","dp","=","DataPack","(","...","relation=relation_df",",","...","left=left",",","...","right=right",",","...",")",">",">",">","len","(","dp",")","2"]
docstr: Apply `func` to text columns based on `mode`.
  
  :param func: The function to apply.
  :param mode: One of "both", "left" and "right".
  :param rename: If set, use new names for results instead of replacing
      the original columns. To set `rename` in "both" mode, use a tuple
      of `str`, e.g. ("text_left_new_name", "text_right_new_name").
  :param inplace: `True` to modify inplace, `False` to return a modified
      copy. (default: `False`)
  :param verbose: Verbosity.
  
  Examples::
      >>> import matchzoo as mz
      >>> data_pack = mz.datasets.toy.load_data()
      >>> frame = data_pack.frame
  
  To apply `len` on the left text and add the result as 'length_left':
      >>> data_pack.apply_on_text(len, mode='left',
      ...                         rename='length_left',
      ...                         inplace=True,
      ...                         verbose=0)
      >>> list(frame[0].columns) # noqa: E501
      ['id_left', 'text_left', 'length_left', 'id_right', 'text_right', 'label']
  
  To do the same to the right text:
      >>> data_pack.apply_on_text(len, mode='right',
      ...                         rename='length_right',
      ...                         inplace=True,
      ...                         verbose=0)
      >>> list(frame[0].columns) # noqa: E501
      ['id_left', 'text_left', 'length_left', 'id_right', 'text_right', 'length_right', 'label']
  
  To do the same to the both texts at the same time:
      >>> data_pack.apply_on_text(len, mode='both',
      ...                         rename=('extra_left', 'extra_right'),
      ...                         inplace=True,
      ...                         verbose=0)
      >>> list(frame[0].columns) # noqa: E501
      ['id_left', 'text_left', 'length_left', 'extra_left', 'id_right', 'text_right', 'length_right', 'extra_right', 'label']
  
  To suppress outputs:
      >>> data_pack.apply_on_text(len, mode='both', verbose=0,
      ...                         inplace=True)
docstr_tok: ["Apply","`","func","`","to","text","columns","based","on","`","mode","`",".",":","param","func",":","The","function","to","apply",".",":","param","mode",":","One","of","``","both","''",",","``","left","''","and","``","right","''",".",":","param","rename",":","If","set",",","use","new","names","for","results","instead","of","replacing","the","original","columns",".","To","set","`","rename","`","in","``","both","''","mode",",","use","a","tuple","of","`","str","`",",","e.g",".","(","``","text_left_new_name","''",",","``","text_right_new_name","''",")",".",":","param","inplace",":","`","True","`","to","modify","inplace",",","`","False","`","to","return","a","modified","copy",".","(","default",":","`","False","`",")",":","param","verbose",":","Verbosity",".","Examples",":",":",">",">",">","import","matchzoo","as","mz",">",">",">","data_pack","=","mz.datasets.toy.load_data","(",")",">",">",">","frame","=","data_pack.frame","To","apply","`","len","`","on","the","left","text","and","add","the","result","as","'length_left","'",":",">",">",">","data_pack.apply_on_text","(","len",",","mode='left","'",",","...","rename='length_left","'",",","...","inplace=True",",","...","verbose=0",")",">",">",">","list","(","frame","[","0","]",".columns",")","#","noqa",":","E501","[","'id_left","'",",","'text_left","'",",","'length_left","'",",","'id_right","'",",","'text_right","'",",","'label","'","]","To","do","the","same","to","the","right","text",":",">",">",">","data_pack.apply_on_text","(","len",",","mode='right","'",",","...","rename='length_right","'",",","...","inplace=True",",","...","verbose=0",")",">",">",">","list","(","frame","[","0","]",".columns",")","#","noqa",":","E501","[","'id_left","'",",","'text_left","'",",","'length_left","'",",","'id_right","'",",","'text_right","'",",","'length_right","'",",","'label","'","]","To","do","the","same","to","the","both","texts","at","the","same","time",":",">",">",">","data_pack.apply_on_text","(","len",",","mode='both","'",",","...","rename=","(","'extra_left","'",",","'extra_right","'",")",",","...","inplace=True",",","...","verbose=0",")",">",">",">","list","(","frame","[","0","]",".columns",")","#","noqa",":","E501","[","'id_left","'",",","'text_left","'",",","'length_left","'",",","'extra_left","'",",","'id_right","'",",","'text_right","'",",","'length_right","'",",","'extra_right","'",",","'label","'","]","To","suppress","outputs",":",">",">",">","data_pack.apply_on_text","(","len",",","mode='both","'",",","verbose=0",",","...","inplace=True",")"]
code: def apply_on_text(
      self,
      func: typing.Callable,
      mode: str = "both",
      rename: typing.Optional[str] = None,
      verbose: int = 1,
  ):
      """
      Apply `func` to text columns based on `mode`.
  
      :param func: The function to apply.
      :param mode: One of "both", "left" and "right".
      :param rename: If set, use new names for results instead of replacing
          the original columns. To set `rename` in "both" mode, use a tuple
          of `str`, e.g. ("text_left_new_name", "text_right_new_name").
      :param inplace: `True` to modify inplace, `False` to return a modified
          copy. (default: `False`)
      :param verbose: Verbosity.
  
      Examples::
          >>> import matchzoo as mz
          >>> data_pack = mz.datasets.toy.load_data()
          >>> frame = data_pack.frame
  
      To apply `len` on the left text and add the result as 'length_left':
          >>> data_pack.apply_on_text(len, mode='left',
          ...                         rename='length_left',
          ...                         inplace=True,
          ...                         verbose=0)
          >>> list(frame[0].columns) # noqa: E501
          ['id_left', 'text_left', 'length_left', 'id_right', 'text_right', 'label']
  
      To do the same to the right text:
          >>> data_pack.apply_on_text(len, mode='right',
          ...                         rename='length_right',
          ...                         inplace=True,
          ...                         verbose=0)
          >>> list(frame[0].columns) # noqa: E501
          ['id_left', 'text_left', 'length_left', 'id_right', 'text_right', 'length_right', 'label']
  
      To do the same to the both texts at the same time:
          >>> data_pack.apply_on_text(len, mode='both',
          ...                         rename=('extra_left', 'extra_right'),
          ...                         inplace=True,
          ...                         verbose=0)
          >>> list(frame[0].columns) # noqa: E501
          ['id_left', 'text_left', 'length_left', 'extra_left', 'id_right', 'text_right', 'length_right', 'extra_right', 'label']
  
      To suppress outputs:
          >>> data_pack.apply_on_text(len, mode='both', verbose=0,
          ...                         inplace=True)
  
      """
      if mode == "both":
          self._apply_on_text_both(func, rename, verbose=verbose)
      elif mode == "left":
          self._apply_on_text_left(func, rename, verbose=verbose)
      elif mode == "right":
          self._apply_on_text_right(func, rename, verbose=verbose)
      else:
          raise ValueError(
              f"{mode} is not a valid mode type."
              f"Must be one of `left` `right` `both`."
          )
  
imports: import typing
  import inspect
  from pathlib import Path
  import functools
  import dill
  from tqdm import tqdm
  import numpy
  import pandas
  import matchzoo
label_desc: Use image node_id 18 for calling the DataPack obj's underlying member method code with example usage: obj.apply_on_text(func, mode, rename, verbose) without return types