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

Import Error/Variable Error in probability.ConditionalFreqDist.plot() #2317

Open
dbalgley opened this issue Jun 12, 2019 · 1 comment
Open

Comments

@dbalgley
Copy link

It seems like changes going back to 42ffffd (2/23/2019) are causing me issues.

  1. On attempting to run example from Chapter 2 of the nltk book (below) I get an ImportError. Seems to be related to the change made on Feb 23 specifically related to the imports:
    cfd = nltk.ConditionalFreqDist( ( genre, word ) for genre in brown.categories( ) for word in brown.words( categories=genre ) ) cfd.plot()

Traceback (most recent call last):
File "C:\XXX\PycharmProjects\ciExp\venv\lib\site-packages\nltk\probability.py", line 1907, in plot
from matplotlib import plt
ImportError: cannot import name 'plt' from 'matplotlib' (C:\XXX\PycharmProjects\ciExp\venv\lib\site-packages\matplotlib_init_.py)

  1. Correcting the import statement to import matplotlib.pyplot as plt as it was before Feb 23 results in an UnboundedLocalError in the same plot() function. There was a change on May 7 to that line where it removed a comment from if v in self:

File "C:\XXX\PycharmProjects\ciExp\venv\lib\site-packages\nltk\probability.py", line 1919, in plot
kwargs, 'samples', sorted(set(v for c in conditions
File "C:\XXX\PycharmProjects\ciExp\venv\lib\site-packages\nltk\probability.py", line 1920, in
if v in self
UnboundLocalError: local variable 'v' referenced before assignment

Code snippet from probability.py:
samples = _get_kwarg( kwargs, 'samples', sorted(set(v for c in conditions if v in self for v in self[c])) ) # this computation could be wasted

  1. Commenting out the if v in self line (probably ill advised but I wanted to walk this back) results in a NameError:

File "C:\XXX\PycharmProjects\ciExp\venv\lib\site-packages\nltk\probability.py", line 1940, in plot
ax.plot(freqs, *args, **kwargs)
NameError: name 'ax' is not defined

I can basically continue to walk this back until the code just hangs infinitely (as far as I can tell). By reverting the probability.py file back before Feb 23, the matplotlib window will show up but (once again, as far as I can tell) it hangs infinitely without showing my data. Other matplotlib function calls seem to work just fine (like those in chapter 1). In my py 3.7 virtenv the version of nltk: 3.4.3 and matplotlib: 3.1.0 so I'm pretty sure it's not an installation issue. Any help would be appreciated!

@BLaZeKiLL
Copy link
Contributor

BLaZeKiLL commented Jun 13, 2019

I am also facing the same issue

I have fixed it (at least it is working for me now) #2319

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants