code: def sample_users(
      data,
      partitions: int,
      size: int,
      method: PartitionMethod,
      disjoint=True,
      *,
      rng_spec=None,
  ):
      """
      Create train-test partitions by sampling users.
      This function does not care what kind of data is in `data`, so long as it is
      a Pandas DataFrame (or equivalent) and has a `user` column.
  
      Args:
          data(pandas.DataFrame):
              Data frame containing ratings or other data you wish to partition.
          partitions(int):
              The number of partitions.
          size(int):
              The sample size.
          method(PartitionMethod):
              The method for obtaining user test ratings.
          rng_spec:
              The random number generator or seed (see :py:func:`seedbank.numpy_rng`).
  
      Returns:
          iterator: An iterator of train-test pairs (as :class:`TTPair` objects).
      """
  
      confirm_unique_index(data)
      rng = numpy_rng(rng_spec)
  
      user_col = data["user"]
      users = user_col.unique()
      if disjoint and partitions * size >= len(users):
          _logger.warning(
              "cannot take %d disjoint samples of size %d from %d users",
              partitions,
              size,
              len(users),
          )
          yield from partition_users(data, partitions, method)
          return
  
      _logger.info(
          "sampling %d users into %d partitions (n=%d)",
          len(users),
          partitions,
          size,
      )
  
      if disjoint:
          rng.shuffle(users)
  
      # generate our samples
      for i in range(partitions):
          # get our test users!
          if disjoint:
              test_us = users[i * size : (i + 1) * size]
          else:
              test_us = rng.choice(users, size, False)
  
          # sample the data frame
          test = (
              data[data.user.isin(test_us)]
              .groupby("user")
              .apply(method)
          )
          # get rid of the group index
          test = test.reset_index(0, drop=True)
          # now test is indexed on the data frame! so we can get the rest
          rest = data.index.difference(test.index)
          train = data.loc[rest]
          yield TTPair(train, test)
  
imports: from collections import namedtuple
  import logging
  from abc import ABC, abstractmethod
  import numpy
  import pandas
  from seedbank import numpy_rng
label_desc: Use image node_id 6 for calling a global function with example usage: sample_users(data, partitions, size, method, disjoint) without return types