code: def test_last_frac():
      ratings = lktu.ml_test.ratings
      users = np.random.choice(ratings.user.unique(), 5, replace=False)
  
      samp = xf.LastFrac(0.2, "timestamp")
      for u in users:
          udf = ratings[ratings.user == u]
          tst = samp(udf)
          trn = udf.loc[udf.index.difference(tst.index), :]
          assert len(tst) + len(trn) == len(udf)
          assert len(tst) >= math.floor(len(udf) * 0.2)
          assert len(tst) <= math.ceil(len(udf) * 0.2)
          assert tst.timestamp.min() >= trn.timestamp.max()
  
      samp = xf.LastFrac(0.5, "timestamp")
      for u in users:
          udf = ratings[ratings.user == u]
          tst = samp(udf)
          trn = udf.loc[udf.index.difference(tst.index), :]
          assert len(tst) + len(trn) == len(udf)
          assert len(tst) >= math.floor(len(udf) * 0.5)
          assert len(tst) <= math.ceil(len(udf) * 0.5)
          assert tst.timestamp.min() >= trn.timestamp.max()
  
imports: import itertools
  import functools
  import pytest
  import math
  import numpy
  import lenskit.util.test
  import lenskit.crossfold
label_desc: Use image node_id 9 for calling a global function with example usage: test_last_frac() without return types