Skip to content

Commit 8d02903

Browse files
committed
BUG: exclude non-numeric data from DataFrame.quantile #2625
1 parent c934e02 commit 8d02903

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

RELEASE.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ pandas 0.10.1
6969
contains NA values (GH2616_)
7070
- Ensure that MultiIndex tuples can be constructed with NAs (seen in #2616)
7171
- Fix int64 overflow issue when unstacking MultiIndex with many levels (#2616)
72+
- Exclude non-numeric data from DataFrame.quantile by default (GH2625_)
7273

7374
**API Changes**
7475

@@ -83,6 +84,7 @@ pandas 0.10.1
8384
.. _GH2585: https://github.com/pydata/pandas/issues/2585
8485
.. _GH2604: https://github.com/pydata/pandas/issues/2604
8586
.. _GH2616: https://github.com/pydata/pandas/issues/2616
87+
.. _GH2625: https://github.com/pydata/pandas/issues/2625
8688

8789
pandas 0.10.0
8890
=============

pandas/core/frame.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4235,7 +4235,7 @@ def applymap(self, func):
42354235
-------
42364236
applied : DataFrame
42374237
"""
4238-
4238+
42394239
# if we have a dtype == 'M8[ns]', provide boxed values
42404240
def infer(x):
42414241
if x.dtype == 'M8[ns]':
@@ -4947,7 +4947,7 @@ def _get_bool_data(self):
49474947
else:
49484948
return self.ix[:, []]
49494949

4950-
def quantile(self, q=0.5, axis=0):
4950+
def quantile(self, q=0.5, axis=0, numeric_only=True):
49514951
"""
49524952
Return values at the given quantile over requested axis, a la
49534953
scoreatpercentile in scipy.stats
@@ -4975,7 +4975,8 @@ def f(arr):
49754975
else:
49764976
return _quantile(arr, per)
49774977

4978-
return self.apply(f, axis=axis)
4978+
data = self._get_numeric_data() if numeric_only else self
4979+
return data.apply(f, axis=axis)
49794980

49804981
def clip(self, upper=None, lower=None):
49814982
"""

pandas/tests/test_frame.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6798,6 +6798,12 @@ def test_quantile(self):
67986798
q = DataFrame({'x':[],'y':[]}).quantile(0.1, axis=0)
67996799
assert(np.isnan(q['x']) and np.isnan(q['y']))
68006800

6801+
# non-numeric exclusion
6802+
df = DataFrame({'col1':['A','A','B','B'], 'col2':[1,2,3,4]})
6803+
rs = df.quantile(0.5)
6804+
xp = df.median()
6805+
assert_series_equal(rs, xp)
6806+
68016807
def test_cumsum(self):
68026808
self.tsframe.ix[5:10, 0] = nan
68036809
self.tsframe.ix[10:15, 1] = nan

0 commit comments

Comments
 (0)