class_docstr: This class extracts a number of basic text descriptives from FeedbackDataset
  records using the TextDescriptives library and adds them as record metadata.
class_docstr_tok: ["This","class","extracts","a","number","of","basic","text","descriptives","from","FeedbackDataset","records","using","the","TextDescriptives","library","and","adds","them","as","record","metadata","."]
docstr: Extract text descriptives metrics for a single field from a list of feedback records
  using the TextDescriptives library.
  
  Args:
      records (List[Union[FeedbackRecord, RemoteFeedbackRecord]]): A list of FeedbackDataset or RemoteFeedbackDataset records.
      field (str): The name of the field to extract metrics for.
      basic_metrics (Optional[List[str]]): A list of basic metrics to extract. If None, all metrics will be extracted.
  
  Returns:
      Optional[pd.DataFrame]: A dataframe containing the text descriptives metrics for the field, or None if the field is empty.
docstr_tok: ["Extract","text","descriptives","metrics","for","a","single","field","from","a","list","of","feedback","records","using","the","TextDescriptives","library",".","Args",":","records","(","List","[","Union","[","FeedbackRecord",",","RemoteFeedbackRecord","]","]",")",":","A","list","of","FeedbackDataset","or","RemoteFeedbackDataset","records",".","field","(","str",")",":","The","name","of","the","field","to","extract","metrics","for",".","basic_metrics","(","Optional","[","List","[","str","]","]",")",":","A","list","of","basic","metrics","to","extract",".","If","None",",","all","metrics","will","be","extracted",".","Returns",":","Optional","[","pd.DataFrame","]",":","A","dataframe","containing","the","text","descriptives","metrics","for","the","field",",","or","None","if","the","field","is","empty","."]
code: def _extract_metrics_for_single_field(
      self,
      records: List[Union[FeedbackRecord, RemoteFeedbackRecord]],
      field: str,
      overwrite: bool = False,
      basic_metrics: Optional[List[str]] = None,
  ) -> Optional[pd.DataFrame]:
      """
      Extract text descriptives metrics for a single field from a list of feedback records
      using the TextDescriptives library.
  
      Args:
          records (List[Union[FeedbackRecord, RemoteFeedbackRecord]]): A list of FeedbackDataset or RemoteFeedbackDataset records.
          field (str): The name of the field to extract metrics for.
          basic_metrics (Optional[List[str]]): A list of basic metrics to extract. If None, all metrics will be extracted.
  
      Returns:
          Optional[pd.DataFrame]: A dataframe containing the text descriptives metrics for the field, or None if the field is empty.
      """
      import textdescriptives as td
  
      def _get_metrics_from_texts(texts: List[str], basic_metrics):
          # If language is english, the default spacy model is used (to avoid warning message)
          field_metrics = td.extract_metrics(
              text=texts, spacy_model=self.model, metrics=self.metrics
          )
          # Drop text column
          field_metrics = field_metrics.drop("text", axis=1)
          # If basic metrics is None, use all basic metrics
          if basic_metrics is None and self.metrics is None:
              basic_metrics = self.__basic_metrics
              field_metrics = field_metrics.loc[:, basic_metrics]
          # Convert any None values to NaNs
          field_metrics = field_metrics.fillna(value=np.nan)
          # Select all column names that contain ONLY NaNs
          nan_columns = field_metrics.columns[
              field_metrics.isnull().all()
          ].tolist()
          if nan_columns:
              warnings.warn(
                  f"The following columns for {field} contain only NaN values: {nan_columns}"
              )
          # Concatenate field name with the metric name
          field_metrics.columns = [
              f"{field}_{metric}" for metric in field_metrics.columns
          ]
          return field_metrics
  
      idx_new = []
      idx_present = []
      data_present: List[dict] = []
      field_text = []
      columns: list[str] = _get_metrics_from_texts(
          ["test"], basic_metrics=basic_metrics
      ).columns.tolist()
      for idx, record in enumerate(records):
          if (
              all([field in record.metadata for field in columns])
              and not overwrite
          ):
              idx_present.append(idx)
              metadata_relevant: dict[str, Any] = {
                  key: record.metadata[key] for key in columns
              }
              data_present.append(metadata_relevant)
          elif record.fields.get(field):
              idx_new.append(idx)
              field_text.append(record.fields[field])
          else:
              idx_present.append(idx)
              data_present.append({key: np.nan for key in columns})
  
      # If the field is empty, skip it
      if not field_text:
          return None
  
      # Extract metrics for the field
      field_metrics_present = pd.DataFrame(
          data_present, index=idx_present
      )
      field_metrics_new = _get_metrics_from_texts(
          field_text, basic_metrics
      )
      field_metrics_new.index = idx_new
  
      # Combine metrics for the field
      field_metrics_combined = pd.concat(
          [field_metrics_present, field_metrics_new]
      )
      field_metrics_combined = field_metrics_combined.sort_index()
  
      return field_metrics_combined
  
imports: import logging
  import re
  import warnings
  from typing import Any, List, Optional, Union
  import numpy
  import pandas
  from rich.progress import Progress
  from argilla.client.feedback.dataset.local.dataset import FeedbackDataset
  from argilla.client.feedback.dataset.remote.dataset import RemoteFeedbackDataset
  from argilla.client.feedback.schemas.metadata import FloatMetadataProperty, IntegerMetadataProperty, TermsMetadataProperty
  from argilla.client.feedback.schemas.records import FeedbackRecord
  from argilla.client.feedback.schemas.remote.records import RemoteFeedbackRecord
  from argilla.utils.dependency import require_dependencies
label_desc: Use image node_id 2 for calling the TextDescriptivesExtractor obj's underlying member method code with example usage: obj._extract_metrics_for_single_field(records, field, overwrite, basic_metrics) and returns: field_metrics_combined, field_metrics, None