Skip to content

Commit

Permalink
fix: is readable - zero division error (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
cachho authored Aug 9, 2023
1 parent ec09a8a commit 65011a6
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion embedchain/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import re
import string

Expand Down Expand Up @@ -43,7 +44,11 @@ def is_readable(s):
:param s: string
:return: True if the string is more than 95% printable.
"""
printable_ratio = sum(c in string.printable for c in s) / len(s)
try:
printable_ratio = sum(c in string.printable for c in s) / len(s)
except ZeroDivisionError:
logging.warning("Empty string processed as unreadable")
printable_ratio = 0
return printable_ratio > 0.95 # 95% of characters are printable


Expand Down

0 comments on commit 65011a6

Please sign in to comment.