code: def test_item_novelty(spark_diversity_data):
      train_df, reco_df, _ = spark_diversity_data
  
      evaluator = SparkDiversityEvaluation(
          train_df=train_df,
          reco_df=reco_df,
          col_user="UserId",
          col_item="ItemId",
      )
      actual = evaluator.historical_item_novelty().toPandas()
      assert_frame_equal(
          pd.DataFrame(
              dict(
                  ItemId=[1, 2, 3, 4, 5],
                  item_novelty=[3.0, 3.0, 2.0, 1.41504, 3.0],
              )
          ),
          actual,
          check_exact=False,
          atol=TOL,
      )
      assert np.all(actual["item_novelty"].values >= 0)
      # Test that novelty is zero when data includes only one item
      train_df_new = train_df.filter("ItemId == 3")
      evaluator = SparkDiversityEvaluation(
          train_df=train_df_new,
          reco_df=reco_df,
          col_user="UserId",
          col_item="ItemId",
      )
      actual = evaluator.historical_item_novelty().toPandas()
      assert actual["item_novelty"].values[0] == 0
  
imports: import pytest
  import numpy
  import pandas
  from pandas.util.testing import assert_frame_equal
  from recommenders.evaluation.python_evaluation import precision_at_k, recall_at_k, ndcg_at_k, map_at_k, map
label_desc: Use image node_id 17 for calling a global function with example usage: test_item_novelty(spark_diversity_data) without return types