code: def test_precision_at_k():
      predictions = pd.Series(
          [["a", "b"], ["c", "d"], ["e"], ["f", "g"]]
      )
      targets = pd.Series([["a", "b"], ["c", "b"], ["e"], ["c"]])
      result = precision_at_k(4).eval_fn(predictions, targets)
  
      assert result.scores == [1.0, 0.5, 1.0, 0.0]
      assert result.aggregate_results == {
          "mean": 2.5 / 4,
          "p90": 1.0,
          "variance": 0.171875,
      }
  
imports: from unittest import mock
  import pandas
  import pytest
  from mlflow.metrics import MetricValue, ari_grade_level, exact_match, f1_score, flesch_kincaid_grade_level, mae, mape, max_error, mse, ndcg_at_k, precision_at_k, precision_score, r2_score, recall_at_k, recall_score, rmse, rouge1, rouge2, rougeL, rougeLsum, toxicity
label_desc: Use image node_id 21 for calling a global function with example usage: test_precision_at_k() without return types