What happened
_mean in unstructured/metrics/utils.py documents "Returns None if no element in the list", but unlike its neighbours _stdev and _pstdev it does not drop None values before averaging:
def _mean(scores: Union[pd.Series, List[float]], rounding: Optional[int] = 3):
if len(scores) == 0:
return None
mean = statistics.mean(scores) # TypeError on a None entry
from unstructured.metrics.utils import _mean, _stdev, _pstdev
_mean([0.9, None, 0.8]) # TypeError: can't convert type 'NoneType' to numerator/denominator
_stdev([0.9, None, 0.8]) # 0.071 (filters None, type hint is List[Optional[float]])
_pstdev([0.9, None, 0.8]) # 0.05 (same)
An unmeasured score is not a score, and the two sibling helpers already treat it that way — including in their type hints (List[Optional[float]]).
Expected
_mean should ignore None entries the same way, and return None when nothing is left to average.
Version
unstructured on main, Python 3.13.
What happened
_meaninunstructured/metrics/utils.pydocuments "Returns None if no element in the list", but unlike its neighbours_stdevand_pstdevit does not dropNonevalues before averaging:An unmeasured score is not a score, and the two sibling helpers already treat it that way — including in their type hints (
List[Optional[float]]).Expected
_meanshould ignoreNoneentries the same way, and returnNonewhen nothing is left to average.Version
unstructuredonmain, Python 3.13.