Repository: pandas-dev/pandas

Issue:
DataFrame.quantile fails with timedelta data

```python
>>> t1 = pd.timedelta_range('1 days', freq='D', periods=5)
>>> t2 = pd.timedelta_range('1 hours', freq='H', periods=5)
>>> df = pd.DataFrame({'t1': t1, 't2': t2})
>>> df.quantile(np.array([0.25, 0.5, 0.75]))
ValueError: need at least one array to concatenate
```
#### Problem description

This works for Series:

```
>>> df['t1'].quantile(np.array([0.25, 0.5, 0.75])) 
0.25   2 days
0.50   3 days
0.75   4 days
Name: t1, dtype: timedelta64[ns]
```

The larger issue is that the `get_numeric_data` in `BlockManager` doesn't pick up timedelta data.

The quantile issue arrises in the `BlockManager` here, https://github.com/pandas-dev/pandas/blob/master/pandas/core/internals.py#L3596, because I  `TimeDeltaBlock`s have `is_numeric=False`. Not entire sure if `is_numeric=True` would be the right fix as it might have impacts downstream (one test in `pandas/tests/frame/test_analytics.py` failed after changing it.)

#### Expected Output

```
pd.concat([df['t1'].quantile(np.array([0.25, 0.5, 0.75])), df['t2'].quantile(np.array([0.25, 0.5, 0.75]))], axis=1) 
         t1       t2
0.25 2 days 02:00:00
0.50 3 days 03:00:00
0.75 4 days 04:00:00

```
#### Output of ``pd.show_versions()``

<details>

INSTALLED VERSIONS
------------------
commit: None
python: 2.7.13.final.0
python-bits: 64
OS: Linux
OS-release: 4.4.0-45-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: None.None

pandas: 0.20.3
pytest: 3.2.1
pip: 9.0.1
setuptools: 27.2.0
Cython: 0.26
numpy: 1.13.1
scipy: 0.19.1
xarray: None
IPython: 5.3.0
sphinx: 1.5.6
patsy: 0.4.1
dateutil: 2.6.1
pytz: 2017.2
blosc: None
bottleneck: 1.2.1
tables: 3.4.2
numexpr: 2.6.2
feather: None
matplotlib: 2.0.2
openpyxl: 2.4.8
xlrd: 1.0.0
xlwt: 1.2.0
xlsxwriter: 0.9.8
lxml: 3.8.0
bs4: 4.3.2
html5lib: 0.9999999
sqlalchemy: 1.1.13
pymysql: 0.7.9.None
psycopg2: 2.7.1 (dt dec pq3 ext lo64)
jinja2: 2.9.6
s3fs: None
pandas_gbq: None
pandas_datareader: None
</details>



Discussion:
@mroeschke : This indeed looks strange.  Poke around to see what fix works best.  If you get stuck, feel free to submit what you have as a PR, and we can examine further.
so we treat Timedelta as non-numeric (like datetime). But some operatators *can* deal with this type of data (e.g. min, max, median, quantile), so this should work (I am pretty sure we test on datetime for this, but obviously not fully on quantile).

Timedeltas are a special beast because they *are* numeric in numpy.
Actually, I just realized this works if `numeric_only=False` is specified:

```
In [9]: df.quantile(np.array([0.25, 0.5, 0.75]), numeric_only=False)
Out[9]:
         t1       t2
0.25 2 days 02:00:00
0.50 3 days 03:00:00
0.75 4 days 04:00:00
```
(As a note, `numeric_only` isn't fully specified in the docstring https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.quantile.html)

I guess the question still stands whether timedelta data should be included if `numeric_only=True` is specified.

Resolving patch:
diff --git a/pandas/core/frame.py b/pandas/core/frame.py
--- a/pandas/core/frame.py
+++ b/pandas/core/frame.py
@@ -7089,6 +7089,9 @@ def quantile(self, q=0.5, axis=0, numeric_only=True,
             0 <= q <= 1, the quantile(s) to compute
         axis : {0, 1, 'index', 'columns'} (default 0)
             0 or 'index' for row-wise, 1 or 'columns' for column-wise
+        numeric_only : boolean, default True
+            If False, the quantile of datetime and timedelta data will be
+            computed as well
         interpolation : {'linear', 'lower', 'higher', 'midpoint', 'nearest'}
             .. versionadded:: 0.18.0
 
@@ -7116,7 +7119,7 @@ def quantile(self, q=0.5, axis=0, numeric_only=True,
         --------
 
         >>> df = pd.DataFrame(np.array([[1, 1], [2, 10], [3, 100], [4, 100]]),
-                           columns=['a', 'b'])
+                              columns=['a', 'b'])
         >>> df.quantile(.1)
         a    1.3
         b    3.7
@@ -7126,6 +7129,20 @@ def quantile(self, q=0.5, axis=0, numeric_only=True,
         0.1  1.3   3.7
         0.5  2.5  55.0
 
+        Specifying `numeric_only=False` will also compute the quantile of
+        datetime and timedelta data.
+
+        >>> df = pd.DataFrame({'A': [1, 2],
+                               'B': [pd.Timestamp('2010'),
+                                     pd.Timestamp('2011')],
+                               'C': [pd.Timedelta('1 days'),
+                                     pd.Timedelta('2 days')]})
+        >>> df.quantile(0.5, numeric_only=False)
+        A                    1.5
+        B    2010-07-02 12:00:00
+        C        1 days 12:00:00
+        Name: 0.5, dtype: object
+
         See Also
         --------
         pandas.core.window.Rolling.quantile


Test patch: