code: def _subsample_one_metric(
      map_df: pd.DataFrame,
      map_key: Optional[str] = None,
      keep_every: Optional[int] = None,
      limit_rows_per_group: Optional[int] = None,
      limit_rows_per_metric: Optional[int] = None,
      include_first_last: bool = True,
  ) -> pd.DataFrame:
      """Helper function to subsample a dataframe that holds a single metric."""
      derived_keep_every = 1
      if keep_every is not None:
          derived_keep_every = keep_every
      elif limit_rows_per_group is not None:
          max_rows = (
              map_df.groupby(MapData.DEDUPLICATE_BY_COLUMNS)
              .size()
              .max()
          )
          derived_keep_every = np.ceil(max_rows / limit_rows_per_group)
      elif limit_rows_per_metric is not None:
          group_sizes = (
              map_df.groupby(MapData.DEDUPLICATE_BY_COLUMNS)
              .size()
              .to_numpy()
          )
          # search for the `keep_every` such that when you apply it to each group,
          # the total number of rows is smaller than `limit_rows_per_metric`.
          for k in range(1, group_sizes.max() + 1):
              if (
                  np.ceil(group_sizes / k)
              ).sum() <= limit_rows_per_metric:
                  derived_keep_every = k
                  break
          # if no such `k` is found, then `derived_keep_every` stays as 1.
  
      if derived_keep_every <= 1:
          filtered_map_df = map_df
      else:
          filtered_dfs = []
          for _, df_g in map_df.groupby(MapData.DEDUPLICATE_BY_COLUMNS):
              df_g = df_g.sort_values(map_key)
              if include_first_last:
                  rows_per_group = int(
                      np.ceil(len(df_g) / derived_keep_every)
                  )
                  linspace_idcs = np.linspace(
                      0, len(df_g) - 1, rows_per_group
                  )
                  idcs = np.round(linspace_idcs).astype(int)
                  filtered_df = df_g.iloc[idcs]
              else:
                  filtered_df = df_g.iloc[:: int(derived_keep_every)]
              filtered_dfs.append(filtered_df)
          filtered_map_df: pd.DataFrame = pd.concat(filtered_dfs)
      return filtered_map_df
  
imports: from __future__ import annotations
  from logging import Logger
  from typing import Any, Dict, Generic, Iterable, List, Optional, Sequence, Type, TypeVar
  import numpy
  import pandas
  from ax.core.data import Data
  from ax.core.types import TMapTrialEvaluation
  from ax.exceptions.core import UnsupportedError
  from ax.utils.common.base import SortableBase
  from ax.utils.common.docutils import copy_doc
  from ax.utils.common.equality import dataframe_equals
  from ax.utils.common.logger import get_logger
  from ax.utils.common.serialization import serialize_init_args, TClassDecoderRegistry, TDecoderRegistry
  from ax.utils.common.typeutils import checked_cast
label_desc: Use image node_id 1 for calling a global function with example usage: _subsample_one_metric(map_df, map_key, keep_every, limit_rows_per_group, limit_rows_per_metric, include_first_last) and returns: filtered_map_df