code: def _maybe_sample(df, sample, random_seed=None):
      """
      Maybe samples the rows of the given df to have at most `sample` rows.
  
      If sample is `None` or falsy, there will be no sampling.
      If the df has fewer rows than the sample, there will be no sampling.
  
      Parameters
      ----------
      df : pandas.DataFrame
          Dataframe that might be sampled
      sample : int or `None`
          Number of rows to be sampled
      random_seed : int or `None`
          Random seed that is forwarded to pandas.DataFrame.sample as `random_state`
  
      Returns
      -------
      pandas.DataFrame
          DataFrame after potential sampling
      """
      if sample and len(df) > sample:
          # this is a problem if x or y have more than sample=5000 categories
          df = df.sample(
              sample, random_state=random_seed, replace=False
          )
      return df
  
imports: import warnings
  import numpy
  import pandas
  from pandas.api.types import is_bool_dtype, is_categorical_dtype, is_datetime64_any_dtype, is_numeric_dtype, is_object_dtype, is_string_dtype, is_timedelta64_dtype
  from sklearn import preprocessing, tree
  from sklearn.metrics import f1_score, mean_absolute_error
  from sklearn.model_selection import cross_val_score
  from deepchecks.utils.typing import Hashable
label_desc: Use image node_id 9 for calling a global function with example usage: _maybe_sample(df, sample, random_seed) and returns: df