<p dir="auto">I have a shuffled series with a bunch of sinvalues in float16, like this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="   tdata.time_sin
   110405276   -0.183105
   175560878   -0.301270
   ...
   130331292   -0.158813
   6782127     -0.282471
    Name: time_sin, Length: 18490389, dtype: float16"><pre class="notranslate"><code class="notranslate">   tdata.time_sin
   110405276   -0.183105
   175560878   -0.301270
   ...
   130331292   -0.158813
   6782127     -0.282471
    Name: time_sin, Length: 18490389, dtype: float16
</code></pre></div>
<p dir="auto">There's no NaN values, everything's a sinus of something:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="tdata.time_sin[np.isnan(tdata.time_sin) == True].count()
0"><pre class="notranslate"><code class="notranslate">tdata.time_sin[np.isnan(tdata.time_sin) == True].count()
0
</code></pre></div>
<p dir="auto">But for some reason, <code class="notranslate">mean() </code>chokes somewhere in the middle like it's overflowing:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="
tdata.time_sin.mean()
nan

tdata.time_sin[:328720].mean()
0.0

tdata.time_sin[:328721].mean()
nan

tdata.time_sin[328719:328722]
117467643   -0.639648
85318746     0.956055
10829780     0.112000
Name: time_sin, dtype: float16"><pre class="notranslate"><code class="notranslate">
tdata.time_sin.mean()
nan

tdata.time_sin[:328720].mean()
0.0

tdata.time_sin[:328721].mean()
nan

tdata.time_sin[328719:328722]
117467643   -0.639648
85318746     0.956055
10829780     0.112000
Name: time_sin, dtype: float16
</code></pre></div>
<p dir="auto">And it works fine when converted to float32:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="foo = tdata.time_sin.astype(np.float32)
foo.mean()

0.20143597"><pre class="notranslate"><code class="notranslate">foo = tdata.time_sin.astype(np.float32)
foo.mean()

0.20143597
</code></pre></div>
<p dir="auto">Is this weird or am I missing something about float16?</p>
<p dir="auto">This behavior persists after pickling and loading and sorting by index, although it now chokes much earlier:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="zzz = pickle.load(open('timesin.pkl', 'rb'))
bb = zzz.sort_index()

bb[:74351].mean()
-0.0

bb[:74352].mean()
nan

bb[74350:74355]
749371   -0.898438
749393   -0.898438
749432   -0.898438
749447   -0.898438
749479   -0.898438
Name: time_sin, dtype: float16
"><pre class="notranslate"><code class="notranslate">zzz = pickle.load(open('timesin.pkl', 'rb'))
bb = zzz.sort_index()

bb[:74351].mean()
-0.0

bb[:74352].mean()
nan

bb[74350:74355]
749371   -0.898438
749393   -0.898438
749432   -0.898438
749447   -0.898438
749479   -0.898438
Name: time_sin, dtype: float16

</code></pre></div>
<h4 dir="auto">Problem description</h4>
<h4 dir="auto">Expected Output</h4>
<h4 dir="auto">Output of <code class="notranslate">pd.show_versions()</code></h4>
<details>
<p dir="auto">pd.show_versions()</p>
<h2 dir="auto">INSTALLED VERSIONS</h2>
<p dir="auto">commit: None<br>
python: 3.5.2.final.0<br>
python-bits: 64<br>
OS: Linux<br>
OS-release: 4.4.0-119-generic<br>
machine: x86_64<br>
processor: x86_64<br>
byteorder: little<br>
LC_ALL: en_US.UTF-8<br>
LANG: en_US.UTF-8<br>
LOCALE: en_US.UTF-8</p>
<p dir="auto">pandas: 0.22.0<br>
pytest: None<br>
pip: 9.0.3<br>
setuptools: 39.0.1<br>
Cython: None<br>
numpy: 1.14.2<br>
scipy: 1.0.1<br>
pyarrow: None<br>
xarray: None<br>
IPython: 6.3.1<br>
sphinx: None<br>
patsy: None<br>
dateutil: 2.7.2<br>
pytz: 2018.3<br>
blosc: None<br>
bottleneck: None<br>
tables: None<br>
numexpr: None<br>
feather: None<br>
matplotlib: 2.2.2<br>
openpyxl: None<br>
xlrd: None<br>
xlwt: None<br>
xlsxwriter: None<br>
lxml: None<br>
bs4: None<br>
html5lib: 1.0.1<br>
sqlalchemy: None<br>
pymysql: None<br>
psycopg2: None<br>
jinja2: 2.10<br>
s3fs: None<br>
fastparquet: None<br>
pandas_gbq: None<br>
pandas_datareader: None</p>
</details>
<p dir="auto">open issues &amp; xref</p>
<ul dir="auto">
<li>(fillna) <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="288078410" data-permission-text="Title is private" data-url="https://github.com/pandas-dev/pandas/issues/19205" data-hovercard-type="issue" data-hovercard-url="/pandas-dev/pandas/issues/19205/hovercard" href="https://github.com/pandas-dev/pandas/issues/19205">#19205</a></li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="89118179" data-permission-text="Title is private" data-url="https://github.com/pandas-dev/pandas/issues/10382" data-hovercard-type="issue" data-hovercard-url="/pandas-dev/pandas/issues/10382/hovercard" href="https://github.com/pandas-dev/pandas/issues/10382">#10382</a></li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="210444839" data-permission-text="Title is private" data-url="https://github.com/pandas-dev/pandas/issues/15517" data-hovercard-type="issue" data-hovercard-url="/pandas-dev/pandas/issues/15517/hovercard" href="https://github.com/pandas-dev/pandas/issues/15517">#15517</a></li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="9240591" data-permission-text="Title is private" data-url="https://github.com/pandas-dev/pandas/issues/2511" data-hovercard-type="issue" data-hovercard-url="/pandas-dev/pandas/issues/2511/hovercard" href="https://github.com/pandas-dev/pandas/issues/2511">#2511</a></li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="235384856" data-permission-text="Title is private" data-url="https://github.com/pandas-dev/pandas/issues/16686" data-hovercard-type="issue" data-hovercard-url="/pandas-dev/pandas/issues/16686/hovercard" href="https://github.com/pandas-dev/pandas/issues/16686">#16686</a></li>
</ul>
<p dir="auto">think this should be a bug. When calling the fill_na method in a pandas Series of type np.float16 it raises a ValueError, because of invalid dtype. May be there is a reason for that I can't guess, but I think it's a bug because it does not detect np.float16 as a subclass of np.floating. I'm using Python 3.4, didn't test if it also fails in Python 2. It fails for both methods, 'pad' and 'bfill'.</p>
<p dir="auto">For np.float32 and np.float64 it works correctly. This code reproduces the error with np.float16:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import numpy as np
import pandas as pd

s = pd.Series(np.random.randn(100), dtype=np.float16)
rets = s.fillna(method='bfill')"><pre class="notranslate"><code class="notranslate">import numpy as np
import pandas as pd

s = pd.Series(np.random.randn(100), dtype=np.float16)
rets = s.fillna(method='bfill')
</code></pre></div>
<p dir="auto">and this is the ValueError it generates:</p>
<hr>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ValueError                                Traceback (most recent call last)
&lt;ipython-input-133-5610749057ca&gt; in &lt;module&gt;()
      3 
      4 s = pd.Series(np.random.randn(100), dtype=np.float16)
----&gt; 5 rets = s.fillna(method='bfill')

/opt/anaconda3/lib/python3.4/site-packages/pandas/core/generic.py in fillna(self, value, method, axis, inplace, limit, downcast)
   2227                                               inplace=inplace,
   2228                                               coerce=True,
-&gt; 2229                                               downcast=downcast)
   2230         else:
   2231             if method is not None:

/opt/anaconda3/lib/python3.4/site-packages/pandas/core/internals.py in interpolate(self, **kwargs)
   2223 
   2224     def interpolate(self, **kwargs):
-&gt; 2225         return self.apply('interpolate', **kwargs)
   2226 
   2227     def shift(self, **kwargs):

/opt/anaconda3/lib/python3.4/site-packages/pandas/core/internals.py in apply(self, f, axes, filter, do_integrity_check, **kwargs)
   2190                                                  copy=align_copy)
   2191 
-&gt; 2192             applied = getattr(b, f)(**kwargs)
   2193 
   2194             if isinstance(applied, list):

/opt/anaconda3/lib/python3.4/site-packages/pandas/core/internals.py in interpolate(self, method, axis, index, values, inplace, limit, fill_value, coerce, downcast, **kwargs)
    648                                                fill_value=fill_value,
    649                                                coerce=coerce,
--&gt; 650                                                downcast=downcast)
    651         # try an interp method
    652         try:

/opt/anaconda3/lib/python3.4/site-packages/pandas/core/internals.py in _interpolate_with_fill(self, method, axis, inplace, limit, fill_value, coerce, downcast)
    693                                     limit=limit,
    694                                     fill_value=fill_value,
--&gt; 695                                     dtype=self.dtype)
    696         values = self._try_coerce_result(values)
    697 

/opt/anaconda3/lib/python3.4/site-packages/pandas/core/common.py in interpolate_2d(values, method, axis, limit, fill_value, dtype)
   1576         values = transf(pad_2d(transf(values), limit=limit, mask=mask, dtype=dtype))
   1577     else:
-&gt; 1578         values = transf(backfill_2d(transf(values), limit=limit, mask=mask, dtype=dtype))
   1579 
   1580     # reshape back

/opt/anaconda3/lib/python3.4/site-packages/pandas/core/common.py in backfill_2d(values, limit, mask, dtype)
   1378 
   1379     if _method is None:
-&gt; 1380         raise ValueError('Invalid dtype for backfill_2d [%s]' % dtype.name)
   1381 
   1382     if mask is None:

ValueError: Invalid dtype for backfill_2d [float16]"><pre class="notranslate"><code class="notranslate">ValueError                                Traceback (most recent call last)
&lt;ipython-input-133-5610749057ca&gt; in &lt;module&gt;()
      3 
      4 s = pd.Series(np.random.randn(100), dtype=np.float16)
----&gt; 5 rets = s.fillna(method='bfill')

/opt/anaconda3/lib/python3.4/site-packages/pandas/core/generic.py in fillna(self, value, method, axis, inplace, limit, downcast)
   2227                                               inplace=inplace,
   2228                                               coerce=True,
-&gt; 2229                                               downcast=downcast)
   2230         else:
   2231             if method is not None:

/opt/anaconda3/lib/python3.4/site-packages/pandas/core/internals.py in interpolate(self, **kwargs)
   2223 
   2224     def interpolate(self, **kwargs):
-&gt; 2225         return self.apply('interpolate', **kwargs)
   2226 
   2227     def shift(self, **kwargs):

/opt/anaconda3/lib/python3.4/site-packages/pandas/core/internals.py in apply(self, f, axes, filter, do_integrity_check, **kwargs)
   2190                                                  copy=align_copy)
   2191 
-&gt; 2192             applied = getattr(b, f)(**kwargs)
   2193 
   2194             if isinstance(applied, list):

/opt/anaconda3/lib/python3.4/site-packages/pandas/core/internals.py in interpolate(self, method, axis, index, values, inplace, limit, fill_value, coerce, downcast, **kwargs)
    648                                                fill_value=fill_value,
    649                                                coerce=coerce,
--&gt; 650                                                downcast=downcast)
    651         # try an interp method
    652         try:

/opt/anaconda3/lib/python3.4/site-packages/pandas/core/internals.py in _interpolate_with_fill(self, method, axis, inplace, limit, fill_value, coerce, downcast)
    693                                     limit=limit,
    694                                     fill_value=fill_value,
--&gt; 695                                     dtype=self.dtype)
    696         values = self._try_coerce_result(values)
    697 

/opt/anaconda3/lib/python3.4/site-packages/pandas/core/common.py in interpolate_2d(values, method, axis, limit, fill_value, dtype)
   1576         values = transf(pad_2d(transf(values), limit=limit, mask=mask, dtype=dtype))
   1577     else:
-&gt; 1578         values = transf(backfill_2d(transf(values), limit=limit, mask=mask, dtype=dtype))
   1579 
   1580     # reshape back

/opt/anaconda3/lib/python3.4/site-packages/pandas/core/common.py in backfill_2d(values, limit, mask, dtype)
   1378 
   1379     if _method is None:
-&gt; 1380         raise ValueError('Invalid dtype for backfill_2d [%s]' % dtype.name)
   1381 
   1382     if mask is None:

ValueError: Invalid dtype for backfill_2d [float16]
</code></pre></div>
<p dir="auto">And my guess is that the problem is this part of the code, I can debug it once you confirm this is a bug:<br>
<a href="https://github.com/pydata/pandas/blob/master/pandas/core/common.py#L2459">https://github.com/pydata/pandas/blob/master/pandas/core/common.py#L2459</a></p>