Skip to content

Commit

Permalink
fix: fix bug in product_weight.py
Browse files Browse the repository at this point in the history
  • Loading branch information
raphael0202 committed Aug 31, 2023
1 parent 5353f1c commit 2e94d11
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions robotoff/prediction/ocr/product_weight.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def normalize_weight(value: str, unit: str) -> tuple[float, str]:
value = str(float(value) * 30)
unit = "ml"

quantity = ureg.parse_expression("{} {}".format(value, unit))
quantity = ureg.parse_expression(f"{value} {unit}")

if ureg.gram in quantity.compatible_units():
normalized_quantity = quantity.to(ureg.gram)
Expand All @@ -40,7 +40,7 @@ def normalize_weight(value: str, unit: str) -> tuple[float, str]:
normalized_quantity = quantity.to(ureg.milliliter)
normalized_unit = "ml"
else:
raise ValueError("unknown unit: {}".format(quantity.u))
raise ValueError(f"unknown unit: {quantity.u}")

return normalized_quantity.magnitude, normalized_unit

Expand Down Expand Up @@ -138,10 +138,10 @@ def process_product_weight(
# Strip value from endpoint point: '525. g' -> '525 g'
value = value.strip(".")

text = "{} {}".format(value, unit)
text = f"{value} {unit}"
normalized_value, normalized_unit = normalize_weight(value, unit)

if is_extreme_weight(normalized_value, unit):
if is_extreme_weight(normalized_value, normalized_unit):
return None

if is_suspicious_weight(normalized_value, normalized_unit):
Expand Down Expand Up @@ -181,7 +181,7 @@ def process_multi_packaging(match) -> Optional[dict]:
return None

normalized_value, normalized_unit = normalize_weight(value, unit)
text = "{} x {} {}".format(count, value, unit)
text = f"{count} x {value} {unit}"
result = {
"text": text,
"raw": raw,
Expand Down

0 comments on commit 2e94d11

Please sign in to comment.