Skip to content

Commit dda2363

Browse files
committed
BUG: don't exclude non-numeric data in groupby.max/min. close #2700
1 parent e05a3d0 commit dda2363

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

RELEASE.rst

+2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ pandas 0.10.1
8888
- Fix DataFrame.from_records corner case when passed columns, index column,
8989
but empty record list (GH2633_)
9090
- Fix C parser-tokenizer bug with trailing fields. (GH2668_)
91+
- Don't exclude non-numeric data from GroupBy.max/min (GH2700_)
9192

9293
**API Changes**
9394

@@ -114,6 +115,7 @@ pandas 0.10.1
114115
.. _GH2690: https://github.com/pydata/pandas/issues/2690
115116
.. _GH2692: https://github.com/pydata/pandas/issues/2692
116117
.. _GH2699: https://github.com/pydata/pandas/issues/2699
118+
.. _GH2700: https://github.com/pydata/pandas/issues/2700
117119

118120
pandas 0.10.0
119121
=============

pandas/core/groupby.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,8 @@ def size(self):
401401

402402
sum = _groupby_function('sum', 'add', np.sum)
403403
prod = _groupby_function('prod', 'prod', np.prod)
404-
min = _groupby_function('min', 'min', np.min)
405-
max = _groupby_function('max', 'max', np.max)
404+
min = _groupby_function('min', 'min', np.min, numeric_only=False)
405+
max = _groupby_function('max', 'max', np.max, numeric_only=False)
406406
first = _groupby_function('first', 'first', _first_compat,
407407
numeric_only=False, _convert=True)
408408
last = _groupby_function('last', 'last', _last_compat, numeric_only=False,

pandas/tests/test_groupby.py

+10
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,16 @@ def _testit(op):
10831083
_testit(lambda x: x.min())
10841084
_testit(lambda x: x.max())
10851085

1086+
def test_max_min_non_numeric(self):
1087+
# #2700
1088+
aa = DataFrame({'nn':[11,11,22,22],'ii':[1,2,3,4],'ss':4*['mama']})
1089+
1090+
result = aa.groupby('nn').max()
1091+
self.assertTrue('ss' in result)
1092+
1093+
result = aa.groupby('nn').min()
1094+
self.assertTrue('ss' in result)
1095+
10861096
def test_cython_agg_boolean(self):
10871097
frame = DataFrame({'a': np.random.randint(0, 5, 50),
10881098
'b': np.random.randint(0, 2, 50).astype('bool')})

0 commit comments

Comments
 (0)