Understanding a traceback error - python

I am trying to understand a traceback error that I am receiving. See below.
Traceback (most recent call last):
File "test.py", line 291, in test_cache_in_function
self.assertTrue("sunset" in testfilestr,"Testing that the sunset request was cached")
AssertionError: Testing that the sunset request was cached
Does the above error mean that "sunset" should not be in the cached file?

A point about nomenclature. You are getting a AssertionError. The error is printed along with the traceback, which indicates the sequence of calls that led to that error.
In your particular case, it looks like the error is caused because the assertion made by self.assertTrue(...) came out False. You are asserting that the string "sunset" is in testfilestr, but it is not. Probably because it is in the cache file instead.
The second argument to assertTrue is a message, which you see as the message to the AssertionError. This argument is optional, and is usually used to clarify the error beyond the obvious default message, which would be something to the effect of "sunset" in testfilestr is False, expected True.

Related

Error for word2vec with GoogleNews-vectors-negative300.bin

the version of python is 3.6
I tried to execute my code but, there are still some errors as below:
Traceback (most recent call last):
File
"C:\Users\tmdgu\Desktop\NLP-master1\NLP-master\Ontology_Construction.py",
line 55, in
, binary=True)
File "E:\Program
Files\Python\Python35-32\lib\site-packages\gensim\models\word2vec.py",
line 1282, in load_word2vec_format
raise DeprecationWarning("Deprecated. Use gensim.models.KeyedVectors.load_word2vec_format instead.")
DeprecationWarning: Deprecated. Use
gensim.models.KeyedVectors.load_word2vec_format instead.
how to fix the code? or is the path to data wrong?
This is just a warning, not a fatal error. Your code likely still works.
"Deprecation" means a function's use has been marked by the authors as no longer encouraged.
The function typically still works, but may not for much longer – becoming unreliable or unavailable in some future library release. Often, there's a newer, more-preferred way to do the same thing, so you don't trigger the warning message.
Your warning message points you at the now-preferred way to load word-vectors of that format: use KeyedVectors.load_word2vec_format() instead.
Did you try using that, instead of whatever line of code (not shown in your question) that you were trying before seeing the warning?

Error Traceback is not descriptive when using multiprocessing pool

Hi i am using python multiprocessing module and the problem is when i get an error from a code that has been executed in another thread, the Traceback is only pointing to multiprocessing/pool.py", line 520 instead of the line number of what caused the error exactly.
Traceback (most recent call last):
File "analyzer.py", line 196, in <module>
for ret in pool.imap(ProcessRow, rows):
File "/usr/lib64/python2.6/multiprocessing/pool.py", line 520, in next
raise value
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
so line 196 in analyzer.py is when i call for ret in pool.imap(ProcessRow, rows):
so it's completely not helpful....Any advice ?
The error is raised from ProcessRow() or some function called by it (why is your function CamelCaseUpper?).
You are not getting a proper stack trace, because the exception is actually pickled from the subprocess (hence the name of the module: multiprocessing) your code is executing in and is then raised again in the manager process. Hence the stack trace shows up as if it was local (while it is actually an exception raised in the subprocess).
The preferred way of dealing with this seems to be to catch the exception in the forked of code and printing a proper stacktrace from there.

Numpy-style error tracebacks?

In numpy, when you make a mistake, the error doesn't tell you about all the numpy internals, just the user-level error made. For example:
import numpy as np
A = np.ones([1,2])
B = np.ones([2,3])
A+B
spits back
Traceback (most recent call last):
File "/home/roderic/Desktop/scratchpad.py", line 5, in <module>
A+B
ValueError: operands could not be broadcast together with shapes (1,2) (2,3)
Notice how it doesn't tell you about all the internal bouncing around that numpy did in order to determine that you are multiplying incompatible matrices, nor where the ValueError was raised exactly. I want to do the same for my project, where the traceback should stop outside of the module internals (unless I am on debug mode). So, if the traceback is 10 steps long, and the first 4 are on user level, and the last 6 are internal processing from my library, I only want to feature the first 4.
I know how to extract the stack, but I don't know how to modify it and re-inject it before raising the exception. I also assume this is considered a bad idea, and if so, I'd like to know what my other options are.
My horrible temporary solution is looking like this:
except AssertionError as error:
# something went wrong, the input was not correct
print( "Traceback (most recent call last):")
for filepath, line_no, namespace, line in traceback.extract_stack():
if os.path.basename(filepath)=='MyModuleName.py': break
print( ' File "{filepath}", line {line_no}, in {namespace}\n'
' {line}'.format(**locals()))
exit()
The only reason that A+B doesn't show any internal stack frames is that numpy.ndarray.__add__() happens to be implemented in C, so there are no Python stack frames after the one containing the A+B to show. numpy is not doing anything special to clean up the stack trace.

Nosetests fails with Pandas

Pandas is not working properly on my system, and I am trying to fix it. Below is the output I got running nosetests pandas (all output available here); do you have any suggestion on how to fix this?
======================================================================
FAIL: test_fred_parts (pandas.io.tests.test_data.TestFred)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/Alberto/anaconda/lib/python2.7/site-packages/pandas/util/testing.py", line 1135, in wrapper
return t(*args, **kwargs)
File "/Users/Alberto/anaconda/lib/python2.7/site-packages/pandas/io/tests/test_data.py", line 424, in test_fred_parts
self.assertEqual(df.ix['2010-05-01'][0], 217.23)
AssertionError: 217.29900000000001 != 217.23
----------------------------------------------------------------------
Ran 4836 tests in 377.165s
FAILED (SKIP=88, failures=2)
This particular test is an "allowable failure" in the pandas network tests (it's decorated as network and I think may have even had to change recently in master to make it less sensitive). Data is grabbed from FRED and parsed and tested against what pandas has queried previously...
Sometimes network tests fails intermittently, it may be that the API has changed, the connection is down, or the numbers have been changed slightly (which from the assertion message looks to be the case here).
This is nothing to worry about, as you can see the other 4836 pass! :)

grid.py not giving output

I am using LibSVM and I used GRID.py for SVM. But the problem is I ran it grid.py more than hour but it's not giving any output. The error message it gives as follows
%%%%%%%%%%%%%%%%%%%%%%%
Traceback (most recent call last):
File "grid.py", line 266, in run
if rate is None: raise RuntimeError('get no rate')
RuntimeError: get no rate
worker local quit.
%%%%%%%%%%%%%%%
Can anybody tell me what's problem? And what is this "worker local quit"?
If anybody want to know more information about implementation or GRID.py please feel free to ask. I am having more than 9000 rows with 8 different columns as dataset
Are you calling GRID.py with either the parameter -log2c or -log2g?
It seems that the problem arises when LocalWorker.run_one returns None.

Categories