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

[BUG] A clear Exception/Error message must be thrown while trying to create a Sentence object from an empty string #565

Closed
bharatr21 opened this issue Feb 25, 2019 · 1 comment
Labels
bug Something isn't working

Comments

@bharatr21
Copy link
Contributor

bharatr21 commented Feb 25, 2019

Describe the bug
If one tries to create a Sentence object from an empty string, an UnboundLocalError of the index variable is thrown

To Reproduce

>>> from flair.data import Sentence
>>> s = ''
>>> Sentence(s)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\XYZ\AppData\Local\Programs\Python\Python36\lib\site-packages\flair\data.py", line 338, in __init__
    index += 1
UnboundLocalError: local variable 'index' referenced before assignment

Expected behavior
Something like ValueError: Cannot create a Sentence object from an empty string or some Error or Exception mentioning that the string is empty or a Sentence object "" - 0 tokens

Environment (please complete the following information):
I feel this is applicable to any OS/version, but anyway:

  • Windows 10
  • flair-0.4.1
  • Python 3.6.8
@bharatr21 bharatr21 added the bug Something isn't working label Feb 25, 2019
@bharatr21
Copy link
Contributor Author

I believe that the if text is not None condition could be changed to if text here to catch the empty string, but I need to know if this could break code elsewhere.
@alanakbik If this is a go, I'm willing to submit a PR 👍

bharatr21 pushed a commit to bharatr21/flair that referenced this issue Feb 25, 2019
kashif pushed a commit that referenced this issue Mar 4, 2019
* Fix #565 by raising ValueError for empty string

* Added unit test for empty string case in PR #566
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

1 participant