code: def run_query(
      df,
      query,
      context_vars=None,
      ignore_empty=False,
      pct=100,
      pct_type="random",
      stratified_group=None,
      highlight_filter=False,
  ):
      """
      Utility function for running :func:`pandas:pandas.DataFrame.query` . This function contains extra logic to
      handle when column names contain special characters.  Looks like pandas will be handling this in a future
      version: https://github.com/pandas-dev/pandas/issues/27017
  
      The logic to handle these special characters in the meantime is only available in Python 3+
  
      :param df: input dataframe
      :type df: :class:`pandas:pandas.DataFrame`
      :param query: query string
      :type query: str
      :param context_vars: dictionary of user-defined variables which can be referenced by name in query strings
      :type context_vars: dict, optional
      :param pct: random percentage of dataframe to load
      :type pct: int, optional
      :param stratified_group: the grouping to use when load a stratified random sample of dataframe
      :type stratified_group: str, optional
      :param highlight_filter: if true, then highlight which rows will be filtered rather than drop them
      :type highlight_filter: boolean, optional
      :return: filtered dataframe
      """
  
      def _load_pct(df):
          if pct is not None and pct < 100:
              if pct_type == "random":
                  return df.sample(frac=pct / 100.0)
              elif pct_type == "stratified":
                  sampling_rate = pct / 100.0
                  num_rows = int((df.shape[0] * sampling_rate) // 1)
                  num_classes = len(df[stratified_group].unique())
                  num_rows_per_class = int(
                      max(1, ((num_rows / num_classes) // 1))
                  )
                  return df.groupby(
                      stratified_group, group_keys=False
                  ).apply(
                      lambda x: x.sample(
                          min(len(x), num_rows_per_class)
                      )
                  )
              records = int(len(df) * (pct / 100.0))
              return (
                  df.head(records)
                  if pct_type == "head"
                  else df.tail(records)
              )
  
          return df
  
      if (query or "") == "":
          if highlight_filter:
              return _load_pct(df), []
          return _load_pct(df)
  
      is_pandas25 = check_pandas_version("0.25.0")
      curr_app_settings = global_state.get_app_settings()
      engine = curr_app_settings.get("query_engine", "python")
      filtered_indexes = []
      if highlight_filter:
          filtered_indexes = set(
              df.query(
                  query if is_pandas25 else query.replace("`", ""),
                  local_dict=context_vars or {},
                  engine=engine,
              ).index
          )
      else:
          df = df.query(
              query if is_pandas25 else query.replace("`", ""),
              local_dict=context_vars or {},
              engine=engine,
          )
  
      if not len(df) and not ignore_empty:
          raise Exception(
              'query "{}" found no data, please alter'.format(query)
          )
  
      if highlight_filter:
          return _load_pct(df), filtered_indexes
      return _load_pct(df)
  
file_path: dtale/dtale/query.py
imports: import pandas
  import dtale.global_state
  from dtale.pandas_util import check_pandas_version
  from dtale.utils import format_data, get_bool_arg
label_desc: Use image node_id 7 for calling a global function with example usage: run_query(df, query, context_vars, ignore_empty, pct, pct_type, stratified_group, highlight_filter) and returns: _load_pct, df, _load_pct, _load_pct,  filtered_indexes, unknown, _load_pct,  list, df, df