docstr: Builds a pandas query from the specified filters.
  
  :param filters: The filters or composite_filters to apply to the
                  dataset.
  :type filters: list[dict]
  :param categorical_features: The categorical feature names.
  :type categorical_features: list[str]
  :param categories: The list of categorical values for the categorical
      features.
  :type categories: list[list]
  :return: The built pandas query from the specified features.
  :rtype: str
docstr_tok: ["Builds","a","pandas","query","from","the","specified","filters",".",":","param","filters",":","The","filters","or","composite_filters","to","apply","to","the","dataset",".",":","type","filters",":","list","[","dict","]",":","param","categorical_features",":","The","categorical","feature","names",".",":","type","categorical_features",":","list","[","str","]",":","param","categories",":","The","list","of","categorical","values","for","the","categorical","features",".",":","type","categories",":","list","[","list","]",":","return",":","The","built","pandas","query","from","the","specified","features",".",":","rtype",":","str"]
code: def _build_query(self, filters, categorical_features, categories):
      """Builds a pandas query from the specified filters.
  
      :param filters: The filters or composite_filters to apply to the
                      dataset.
      :type filters: list[dict]
      :param categorical_features: The categorical feature names.
      :type categorical_features: list[str]
      :param categories: The list of categorical values for the categorical
          features.
      :type categories: list[list]
      :return: The built pandas query from the specified features.
      :rtype: str
      """
      queries = []
      for filter in filters:
          if METHOD in filter:
              method = filter[METHOD]
              arg0 = str(filter[ARG][0])
              colname = filter[COLUMN]
              if colname == "True Y":
                  colname = TRUE_Y
              if method == CohortFilterMethods.METHOD_GREATER:
                  queries.append("`" + colname + "` > " + arg0)
              elif method == CohortFilterMethods.METHOD_LESS:
                  queries.append("`" + colname + "` < " + arg0)
              elif method == CohortFilterMethods.METHOD_LESS_AND_EQUAL:
                  queries.append("`" + colname + "` <= " + arg0)
              elif (
                  method == CohortFilterMethods.METHOD_GREATER_AND_EQUAL
              ):
                  queries.append("`" + colname + "` >= " + arg0)
              elif method == CohortFilterMethods.METHOD_RANGE:
                  arg1 = str(filter[ARG][1])
                  queries.append(
                      "`"
                      + colname
                      + "` >= "
                      + arg0
                      + " & `"
                      + colname
                      + "` <= "
                      + arg1
                  )
              elif (
                  method == CohortFilterMethods.METHOD_INCLUDES
                  or method == CohortFilterMethods.METHOD_EXCLUDES
              ):
                  query = self._build_bounds_query(
                      filter,
                      colname,
                      method,
                      categorical_features,
                      categories,
                  )
                  queries.append(query)
              elif method == CohortFilterMethods.METHOD_EQUAL:
                  is_categorical = False
                  if categorical_features:
                      is_categorical = colname in categorical_features
                  if is_categorical:
                      cat_idx = categorical_features.index(colname)
                      arg0i = filter[ARG][0]
                      arg_cat = categories[cat_idx][arg0i]
                      if isinstance(arg_cat, str):
                          queries.append(
                              "`{}` == '{}'".format(colname, arg_cat)
                          )
                      else:
                          queries.append(
                              "`{}` == {}".format(colname, arg_cat)
                          )
                  else:
                      queries.append("`" + colname + "` == " + arg0)
              else:
                  raise ValueError(
                      "Unsupported method type: {}".format(method)
                  )
          else:
              cqueries = []
              for composite_filter in filter[COMPOSITE_FILTERS]:
                  cqueries.append(
                      self._build_query(
                          [composite_filter],
                          categorical_features,
                          categories,
                      )
                  )
              if filter[OPERATION] == CohortFilterOps.AND:
                  queries.append("(" + ") & (".join(cqueries) + ")")
              else:
                  queries.append("(" + ") | (".join(cqueries) + ")")
      return "(" + ") & (".join(queries) + ")"
  
file_path: responsible-ai-toolbox/erroranalysis/erroranalysis/_internal/cohort_filter.py
imports: from typing import Any, List, Optional
  import numpy
  import pandas
  from erroranalysis._internal.constants import ARG, COLUMN, COMPOSITE_FILTERS, METHOD, OPERATION, PRED_Y, ROW_INDEX, TRUE_Y, CohortFilterMethods, CohortFilterOps, ModelTask
  from erroranalysis._internal.metrics import get_ordered_classes
  from erroranalysis._internal.utils import is_spark
label_desc: Use image node_id 11 for calling the FilterDataWithCohortFilters obj's underlying member method code with example usage: obj._build_query(filters, categorical_features, categories) and returns: unknown