Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZeroDivisionError in in_target_language #18

Closed
osma opened this issue Sep 29, 2022 · 1 comment
Closed

ZeroDivisionError in in_target_language #18

osma opened this issue Sep 29, 2022 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@osma
Copy link
Contributor

osma commented Sep 29, 2022

Hello,

while testing Simplemma language detection in Annif (see NatLibFi/Annif#626), I stumbled on a ZeroDivisionError when calling in_target_language. It's pretty easy to trigger for example by passing an empty string:

>>> from simplemma.langdetect import in_target_language
>>> in_target_language('', lang='en')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/oisuomin/.cache/pypoetry/virtualenvs/annif-3KgT0m3n-py3.8/lib/python3.8/site-packages/simplemma/langdetect.py", line 54, in in_target_language
    return in_target / total
ZeroDivisionError: division by zero

Other inputs can trigger this as well, for example any string that consists of only punctuation and/or spaces.

I can work around this in the calling code but I think it would be worth fixing in Simplemma itself.

@adbar
Copy link
Owner

adbar commented Oct 4, 2022

Hi @osma, thanks for reporting the issue, I'll work on a fix.

@adbar adbar self-assigned this Oct 4, 2022
@adbar adbar added the bug Something isn't working label Oct 4, 2022
@adbar adbar closed this as completed in c87066a Oct 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants