Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion unstructured/metrics/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,21 @@ def _mean(scores: Union[pd.Series, List[float]], rounding: Optional[int] = 3) ->
"""
if len(scores) == 0:
return None
mean = statistics.mean(scores)
if isinstance(scores, pd.Series):
mean = scores.mean(skipna=False)
# Convert numpy scalar to Python native type
if hasattr(mean, "item"):
mean = mean.item()
else:
total = sum(scores)
mean = total / len(scores)
# Preserve int type if all inputs are ints and result is whole number
if (
all(isinstance(x, int) for x in scores)
and isinstance(total, int)
and total % len(scores) == 0
):
mean = int(mean)
if not rounding:
return mean
return round(mean, rounding)
Expand Down