code: def test_pop_candidates():
      algo = basic.Popular()
      algo.fit(lktu.ml_test.ratings)
      counts = lktu.ml_test.ratings.groupby("item").user.count()
      items = lktu.ml_test.ratings.item.unique()
  
      assert algo.item_pop_.max() == counts.max()
  
      candidates = np.random.choice(items, 500, replace=False)
  
      recs = algo.recommend(2038, 100, candidates)
      assert len(recs) == 100
      assert all(np.diff(recs.score) <= 0)
  
      ccs = counts.loc[candidates]
      ccs = ccs.sort_values(ascending=False)
  
      assert recs.score.iloc[0] == ccs.max()
      equiv = ccs[ccs == ccs.max()]
      assert recs.item.iloc[0] in equiv.index
  
file_path: lkpy/tests/test_popular.py
imports: from lenskit.algorithms import basic
  import pandas
  import numpy
  import pickle
  import lenskit.util.test
label_desc: Use image node_id 3 for calling a global function with example usage: test_pop_candidates() without return types