From 9828f7085264e734cead4dd3bf64f7571aa4c3b4 Mon Sep 17 00:00:00 2001 From: YousefZahran1 Date: Thu, 7 May 2026 18:58:16 +0300 Subject: [PATCH] fix: raise clear ValueError when add_batch receives None inputs Previously, passing None as predictions or references to add_batch() caused a cryptic 'TypeError: object of type NoneType has no len()' deep inside the Arrow serialisation path (module.py:518), making it hard to diagnose. The TypeError was re-raised from inside the except handler (line 523), which also called len() on the None value and crashed again. Fix: validate the batch dict immediately after construction and raise a descriptive ValueError that names the offending fields and directs the user to check their compute_metrics function. Fixes #668 --- src/evaluate/module.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/evaluate/module.py b/src/evaluate/module.py index ca38b9b1..d1591014 100644 --- a/src/evaluate/module.py +++ b/src/evaluate/module.py @@ -510,6 +510,13 @@ def add_batch(self, *, predictions=None, references=None, **kwargs): ) batch = {"predictions": predictions, "references": references, **kwargs} batch = {input_name: batch[input_name] for input_name in self._feature_names()} + none_inputs = [name for name, val in batch.items() if val is None] + if none_inputs: + raise ValueError( + f"Batch inputs contain None for the following fields: {none_inputs}. " + "All inputs must be non-None sequences (lists, arrays, or tensors). " + "Check that your compute_metrics function passes non-None predictions and references." + ) if self.writer is None: self.selected_feature_format = self._infer_feature_from_batch(batch) self._init_writer()