Repository: pandas-dev/pandas

Issue:
TypeError: Cannot interpolate with all NaNs.
#### Problem description

I got an error: "TypeError: Cannot interpolate with all NaNs." This error was raised on line 6011 of pandas\core\generic.py. Sorry, I'm not able to provide a simple code sample to reproduce the problem. 

I can't see why this error should ever be raised. If the input is all NaNs, interpolate() should output all NaNs. Users of interpolate() don't necessarily know what data they will get. Why make them handle this error?

#### Expected Output
All NaNs

#### Output of ``pd.show_versions()``

<details>

[paste the output of ``pd.show_versions()`` here below this line]
INSTALLED VERSIONS
------------------
commit: None
python: 3.6.5.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 158 Stepping 9, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None

pandas: 0.23.0
pytest: 3.5.1
pip: 10.0.1
setuptools: 39.1.0
Cython: 0.28.2
numpy: 1.14.3
scipy: 1.1.0
pyarrow: None
xarray: None
IPython: 6.4.0
sphinx: 1.7.4
patsy: 0.5.0
dateutil: 2.7.3
pytz: 2018.4
blosc: None
bottleneck: 1.2.1
tables: 3.4.3
numexpr: 2.6.5
feather: None
matplotlib: 2.2.2
openpyxl: 2.5.3
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 1.0.4
lxml: 4.2.1
bs4: 4.6.0
html5lib: 1.0.1
sqlalchemy: 1.2.7
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
</details>



Discussion:
Let us know if you can provide a minimal example: http://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports
@david-r-wasserman I think the problem is you have dtype=object:

```python3
In [26]: pd.DataFrame({'a':pd.Series([2, 3, 1])}).interpolate()
Out[26]:
   a
0  2
1  3
2  1

In [27]: pd.DataFrame({'a':pd.Series([2, 3, 1], dtype=object)}).interpolate()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-27-87d427d43aa7> in <module>()
----> 1 pd.DataFrame({'a':pd.Series([2, 3, 1], dtype=object)}).interpolate()

C:\Miniconda2\lib\site-packages\pandas\core\generic.pyc in interpolate(self, method, axis, limit, inplace, limit_direction, downcast, **kwargs)
   3668         if _maybe_transposed_self._data.get_dtype_counts().get(
   3669                 'object') == len(_maybe_transposed_self.T):
-> 3670             raise TypeError("Cannot interpolate with all NaNs.")
   3671
   3672         # create/use the index

TypeError: Cannot interpolate with all NaNs.
```

@TomAugspurger I think the `TypeError` here is confusing. The code check is that all columns of the DataFrame have dtype object, but the message says there's a problem with NaNs, even if the dataset has no NaNs.
Agreed, that's a confusing error message... It's also not really clear to me why we're doing that in the first place (and I think I wrote that code 😄). Any investigation here would be welcome.
Yup, it's your commit (from 2013!), revision aff7346f3be41d1b190f311f862653b6088e2ad7 added

```python3
        if self._data.get_dtype_counts().get('object') == len(self.T):
            raise TypeError("Cannot interpolate with all NaNs.")
```

That one commit added basically all the type checking currently in the function.. Only thought is that right below in the same commit is another check:

```python3
        if pd.isnull(index).any():
            raise NotImplementedError("Interpolation with NaNs in the index "
                                      "has not been implemented. Try filling "
                                      "those NaNs before interpolating.")
```

At this point I assume you meant to write TypeError("Cannot interpolate with all objects"), had the second check on the brain and typoed?


Resolving patch:
diff --git a/pandas/core/generic.py b/pandas/core/generic.py
--- a/pandas/core/generic.py
+++ b/pandas/core/generic.py
@@ -6387,7 +6387,9 @@ def interpolate(self, method='linear', axis=0, limit=None, inplace=False,
 
         if _maybe_transposed_self._data.get_dtype_counts().get(
                 'object') == len(_maybe_transposed_self.T):
-            raise TypeError("Cannot interpolate with all NaNs.")
+            raise TypeError("Cannot interpolate with all object-dtype columns "
+                            "in the DataFrame. Try setting at least one "
+                            "column to a numeric dtype.")
 
         # create/use the index
         if method == 'linear':


Test patch:
diff --git a/pandas/tests/frame/test_missing.py b/pandas/tests/frame/test_missing.py
--- a/pandas/tests/frame/test_missing.py
+++ b/pandas/tests/frame/test_missing.py
@@ -814,6 +814,19 @@ def test_interp_raise_on_only_mixed(self):
         with pytest.raises(TypeError):
             df.interpolate(axis=1)
 
+    def test_interp_raise_on_all_object_dtype(self):
+        # GH 22985
+        df = DataFrame({
+            'A': [1, 2, 3],
+            'B': [4, 5, 6]},
+            dtype='object')
+        with tm.assert_raises_regex(
+                TypeError,
+                "Cannot interpolate with all object-dtype columns "
+                "in the DataFrame. Try setting at least one "
+                "column to a numeric dtype."):
+            df.interpolate()
+
     def test_interp_inplace(self):
         df = DataFrame({'a': [1., 2., np.nan, 4.]})
         expected = DataFrame({'a': [1., 2., 3., 4.]})