code: def partition_users(
      data, partitions: int, method: PartitionMethod, *, rng_spec=None
  ):
      """
      Partition a frame of ratings or other data into train-test partitions user-by-user.
      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): a data frame containing ratings or other data you wish to partition.
          partitions(int): the number of partitions to produce
          method(PartitionMethod): The method for selecting test rows for each user.
          rng_spec: The random number generator or seed (see :py:func:`seedbank.numpy_rng`).
  
      Returns
          iterator: an iterator of train-test pairs
      """
  
      confirm_unique_index(data)
      user_col = data["user"]
      users = user_col.unique()
      _logger.info(
          "partitioning %d rows for %d users into %d partitions",
          len(data),
          len(users),
          partitions,
      )
  
      # create an array of indexes into user row
      rows = np.arange(len(users))
      # shuffle the indices & split into partitions
      rng = numpy_rng(rng_spec)
      rng.shuffle(rows)
      test_sets = np.array_split(rows, partitions)
  
      # convert each partition into a split
      for i, ts in enumerate(test_sets):
          # get our users!
          test_us = users[ts]
          # sample the data frame
          _logger.info("fold %d: selecting test ratings", i)
          ugf = data[data.user.isin(test_us)].groupby("user")
          test = ugf.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
          _logger.info("fold %d: partitioning training data", i)
          mask = pd.Series(True, index=data.index)
          mask[test.index] = False
          train = data[mask]
          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 5 for calling a global function with example usage: partition_users(data, partitions, method) without return types