Note that there are some explanatory texts on larger screens.

plurals
  1. POPython throws TypeError on issubclass() when issubclass() is never called
    primarykey
    data
    text
    <p>I have a piece of code that runs perfectly most of the time, but every once in awhile I get this error in the traceback:</p> <pre><code>File "/path/to/somefile.py", line 272, in somefile sm = -0.5 * (wv[0]**2. / sm2 + numpy.log(2. * numpy.pi * sm2)) TypeError: issubclass() arg 2 must be a class or tuple of classes </code></pre> <p>I know what <code>issubclass()</code> does and understand the error, but I never called it; that line in the code is pure arithmetic, so I don't know why this <code>TypeError</code> is raised in the first place. My only theory is that Numpy is calling it behind the scenes, but then the traceback should show the problematic line in the Numpy source, right? What's going on?</p> <p><strong>Updates:</strong></p> <p><code>wv</code> is an array of floats and <code>sm2</code> is a float scalar. The error is actually thrown by <code>numpy.log</code>, i.e. the (new) line</p> <pre><code>tmp = numpy.log(2. * numpy.pi * sm2) </code></pre> <p>No more information is provided in the error message, though.</p> <p><strong>More updates:</strong></p> <p>My current version of Numpy (from a Python prompt):</p> <pre><code>&gt;&gt;&gt; import numpy &gt;&gt;&gt; numpy.__version__ '1.6.2' </code></pre> <p>I changed the problem line to</p> <pre><code>try: tmp = numpy.log(2. * numpy.pi * sm2) except TypeError: print type(sm2), 2. * numpy.pi * sm2 </code></pre> <p>and got the output</p> <pre><code>&lt;type 'numpy.float64'&gt; 0.0 </code></pre> <p>So it makes sense that there would be <em>some kind</em> of error, but if I do this (at a Python prompt)</p> <pre><code>&gt;&gt;&gt; import numpy &gt;&gt;&gt; numpy.log(0.) </code></pre> <p>I get the error I would expect (and am already handling in the code in question, via the <code>warning</code> module):</p> <pre><code>__main__:1: RuntimeWarning: divide by zero encountered in log -inf </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload