{"record":{"id":"b7618c73ffe7507f","repo":"tensorflow/models","slug":"top-n-must-be-a-positive-integer-or-none","errorCode":null,"errorMessage":"top_n must be a positive integer or None.","messagePattern":"top_n must be a positive integer or None\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/projects/yt8m/eval_utils/average_precision_calculator.py","lineNumber":77,"sourceCode":"\n\nclass AveragePrecisionCalculator(object):\n  \"\"\"Calculate the average precision and average precision at n.\"\"\"\n\n  def __init__(self, top_n=None):\n    \"\"\"Construct an AveragePrecisionCalculator to calculate average precision.\n\n    This class is used to calculate the average precision for a single label.\n\n    Args:\n      top_n: A positive Integer specifying the average precision at n, or None\n        to use all provided data points.\n\n    Raises:\n      ValueError: An error occurred when the top_n is not a positive integer.\n    \"\"\"\n    if not ((isinstance(top_n, int) and top_n >= 0) or top_n is None):\n      raise ValueError(\"top_n must be a positive integer or None.\")\n\n    self._top_n = top_n  # average precision at n\n    self._total_positives = 0  # total number of positives have seen\n    self._heap = []  # max heap of (prediction, actual)\n\n  @property\n  def heap_size(self):\n    \"\"\"Gets the heap size maintained in the class.\"\"\"\n    return len(self._heap)\n\n  @property\n  def num_accumulated_positives(self):\n    \"\"\"Gets the number of positive samples that have been accumulated.\"\"\"\n    return self._total_positives\n\n  def accumulate(self, predictions, actuals, num_positives=None):\n    \"\"\"Accumulate the predictions and their ground truth labels.\n","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/projects/yt8m/eval_utils/average_precision_calculator.py#L59-L95","documentation":"Error \"top_n must be a positive integer or None.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/projects/yt8m/eval_utils/average_precision_calculator.py:77 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e006f5f0d534913e49c1f1dae87364039fa607e2","analyzedAt":"2026-08-24T14:09:15.576Z","schemaVersion":2},"datasetVersion":"2026-08-24T17:17:21.512Z"}