code: def test_python_ndcg_at_k(rating_true, rating_pred, rating_nohit):
      assert ndcg_at_k(
          rating_true=rating_true,
          rating_pred=rating_true,
          col_prediction=DEFAULT_RATING_COL,
          k=10,
      ) == pytest.approx(1.0, TOL)
      assert ndcg_at_k(rating_true, rating_nohit, k=10) == 0.0
      assert ndcg_at_k(rating_true, rating_pred, k=10) == pytest.approx(
          0.38172, TOL
      )
  
      # Test raw relevance score and log2 discounting factor using wiki example
      # See https://en.wikipedia.org/wiki/Discounted_cumulative_gain
      df_true = pd.DataFrame(
          {
              DEFAULT_USER_COL: np.full(8, 0, dtype=int),
              DEFAULT_ITEM_COL: np.arange(8),
              DEFAULT_RATING_COL: np.asarray([3, 2, 3, 0, 1, 2, 3, 2]),
          }
      )
      df_pred = pd.DataFrame(
          {
              DEFAULT_USER_COL: np.full(6, 0, dtype=int),
              DEFAULT_ITEM_COL: np.arange(6),
              DEFAULT_PREDICTION_COL: np.asarray([6, 5, 4, 3, 2, 1]),
          }
      )
      assert ndcg_at_k(
          df_true, df_pred, k=6, score_type="raw", discfun_type="log2"
      ) == pytest.approx(0.785, TOL)
  
imports: import numpy
  import pandas
  import pytest
  from unittest.mock import Mock
  from sklearn.preprocessing import minmax_scale
  from pandas.testing import assert_frame_equal
  from recommenders.utils.constants import DEFAULT_USER_COL, DEFAULT_ITEM_COL, DEFAULT_RATING_COL, DEFAULT_PREDICTION_COL
  from recommenders.evaluation.python_evaluation import _check_column_dtypes, merge_rating_true_pred, merge_ranking_true_pred, rmse, mae, rsquared, exp_var, get_top_k_items, precision_at_k, recall_at_k, ndcg_at_k, map_at_k, map, auc, logloss, user_diversity, diversity, historical_item_novelty, novelty, user_item_serendipity, user_serendipity, serendipity, catalog_coverage, distributional_coverage, ColumnMismatchError, ColumnTypeMismatchError
label_desc: Use image node_id 12 for calling a global function with example usage: test_python_ndcg_at_k(rating_true, rating_pred, rating_nohit) without return types