Skip to content

_mean raises TypeError on a score list containing None, unlike _stdev and _pstdev #4509

Description

@sclfcz

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions