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

Python 3.7.3, gensim 3.8.1: UnboundLocalError: local variable 'doc_no2' referenced before assignment #2670

Closed
paulrigor opened this issue Nov 7, 2019 · 4 comments · Fixed by #2672
Labels
bug Issue described a bug difficulty easy Easy issue: required small fix impact HIGH Show-stopper for affected users reach LOW Affects only niche use-case users

Comments

@paulrigor
Copy link
Contributor

paulrigor commented Nov 7, 2019

Client code:
model = LogEntropyModel(corpus=data_corpus, normalize=True)
Referenced code:
https://github.com/RaRe-Technologies/gensim/blob/44ea7931c916349821aa1c717fbf7e90fb138297/gensim/models/logentropy_model.py#L115

Exception thrown:

  File "/anaconda3/lib/python3.7/site-packages/gensim/models/logentropy_model.py", line 76, in __init__
    self.initialize(corpus)
  File "/anaconda3/lib/python3.7/site-packages/gensim/models/logentropy_model.py", line 115, in initialize
    if doc_no2 != doc_no:
UnboundLocalError: local variable 'doc_no2' referenced before assignment

@piskvorky
Copy link
Owner

piskvorky commented Nov 7, 2019

Looks like a programming bug to me. doc_no2 should be initialized to zero, in case the corpus/generator is empty (which is what this block is actually testing).

Thanks for reporting.

@piskvorky piskvorky added bug Issue described a bug difficulty easy Easy issue: required small fix impact HIGH Show-stopper for affected users reach LOW Affects only niche use-case users labels Nov 7, 2019
@paulrigor
Copy link
Contributor Author

I can try to patch it. I'll update and cut a PR when ready. Cheers!

@paulrigor
Copy link
Contributor Author

@piskvorky, Here's the PR for the simple patch:

#2672

@mpenkov
Copy link
Collaborator

mpenkov commented Nov 10, 2019

@paulrigor The existing tests pass.

Can you please add a new unit test to cover the bug you fixed? The test should fail without your change, and pass once your change is in place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue described a bug difficulty easy Easy issue: required small fix impact HIGH Show-stopper for affected users reach LOW Affects only niche use-case users
Projects
None yet
3 participants