<p dir="auto">Hi, everyone</p>
<p dir="auto">According to <a href="http://docs.scipy.org/doc/numpy-dev/reference/c-api.coremath.html#half-precision-functions" rel="nofollow">documentation</a>, <code class="notranslate">np.float16</code> should <strong>not</strong> be used in C code as it is right now in pandas/algos.pyx:38 (assigning <code class="notranslate">np.NINF</code> to a <code class="notranslate">np.float16</code> container in "cython-eventually-converted-to-C" code</p>
<p dir="auto">As a matter of fact, when this value/variable is exposed, it is exposed as <code class="notranslate">0.0</code>, and not <code class="notranslate">-inf</code>, either in C/C++ while using gdb or even with python.</p>
<p dir="auto">Since <code class="notranslate">MINfloat6</code> it is not being used in all pandas code, I recommend eliminating this line and/or commentating the reason. I tried by using <code class="notranslate">np.float16(np.NINF)</code> but the problem is that a correct C <code class="notranslate">-inf</code> value is <strong>still</strong> being C-assigned to a please-don't-use-C-container.</p>
<p dir="auto">Why is it that this is important to me/I got to find this error? I'm dealing with 3rd party code so I cannot get a configuration that allows me to do this assignment without raising SIGFPE.</p>
<p dir="auto">No pull request? The two possible solutions to me is either using cython-kept-as-python code with just this variable (which would impact performance) or simply not using it at all. I think I don't have the authority for either.</p>
<p dir="auto">The code generated by Cython from pandas/algos.pyx contains an undefined behavior (invalid cast of floating-point number to integer):</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="easy_install -U Cython
git clone git://github.com/pydata/pandas.git
python setup.py install"><pre class="notranslate"><code class="notranslate">easy_install -U Cython
git clone git://github.com/pydata/pandas.git
python setup.py install
</code></pre></div>
<p dir="auto">The generated code for the line from <code class="notranslate">pandas/algos.pyx</code></p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="cdef np.float16_t MINfloat16 = np.NINF"><pre class="notranslate"><span class="pl-s1">cdef</span> <span class="pl-s1">np</span>.<span class="pl-s1">float16_t</span> <span class="pl-v">MINfloat16</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-v">NINF</span></pre></div>
<p dir="auto">in <code class="notranslate">pandas/algos.c</code> contains:</p>
<div class="highlight highlight-source-c notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="typedef npy_float16 __pyx_t_5numpy_float16_t;
//... more code
__pyx_t_5numpy_float16_t __pyx_t_10;
//... more code
__pyx_t_10 = __pyx_PyFloat_AsFloat(__pyx_t_1);"><pre class="notranslate"><span class="pl-k">typedef</span> <span class="pl-smi">npy_float16</span> <span class="pl-smi">__pyx_t_5numpy_float16_t</span>;
<span class="pl-c">//... more code</span>
<span class="pl-smi">__pyx_t_5numpy_float16_t</span> <span class="pl-s1">__pyx_t_10</span>;
<span class="pl-c">//... more code</span>
<span class="pl-s1">__pyx_t_10</span> <span class="pl-c1">=</span> <span class="pl-en">__pyx_PyFloat_AsFloat</span>(<span class="pl-s1">__pyx_t_1</span>);</pre></div>
<p dir="auto">The file <code class="notranslate">numpy-1.9.2-py2.7-linux-x86_64.egg/numpy/core/include/numpy/npy_common.h</code><br>
defines <code class="notranslate">npy_float16</code> as 16-bit <em>integer</em> type (I guess numpy implementation has a custom code that carefully represents these 16 bits as mantiss+exponent). Casting floating-point value <code class="notranslate">-inf</code> to a 16-bit integer type is an undefined behavior according to C standard.</p>
<p dir="auto">I wasn't able to find any place in pandas code that uses <code class="notranslate">MINfloat16</code> (and <code class="notranslate">MAXfloat16</code>). Is it safe to just delete them?</p>