MEDIUM SEVERITYCONFIRMED

DataCompyScore raises ZeroDivisionError when both precision and recall are zero

Package
ragas
Version
0.4.3
Verified
2026-03-28

Description

The legacy `metrics/_datacompy_score.py` computes F1 score as `2 * (precision * recall) / (precision + recall)` without guarding against the case where both are zero. When `count_matching_rows()` returns 0 for both DataFrames, `precision = 0.0` and `recall = 0.0`, and the division raises `ZeroDivisionError`. The newer `collections/datacompy_score/metric.py` fixes this, but the legacy path — which is the exported default — does not.

Reproduction

precision = 0.0
recall = 0.0
result = 2 * (precision * recall) / (precision + recall)
# ZeroDivisionError: float division by zero
# This is the exact code path in metrics/_datacompy_score.py:75
← All bugsScan your code →