Skip to content

Commit fb42041

Browse files
committed
Implement mode(dropna), for pandas-dev#17534
1 parent 328c7e1 commit fb42041

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

pandas/core/algorithms.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -634,14 +634,16 @@ def duplicated(values, keep='first'):
634634
return f(values, keep=keep)
635635

636636

637-
def mode(values):
637+
def mode(values, dropna=True):
638638
"""
639639
Returns the mode(s) of an array.
640640
641641
Parameters
642642
----------
643643
values : array-like
644-
Array over which to check for duplicate values.
644+
Array over which to check for duplicate values
645+
dropna : boolean, default True
646+
Don't include NaN values.
645647
646648
Returns
647649
-------
@@ -666,6 +668,7 @@ def mode(values):
666668
ndtype = 'object'
667669
values = _ensure_object(values)
668670

671+
### TODO: IN HERE IMPLEMENT THE DROPNA PARAMETER
669672
f = getattr(htable, "mode_{dtype}".format(dtype=ndtype))
670673
result = f(values)
671674
try:

pandas/core/frame.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -5640,7 +5640,7 @@ def _get_agg_axis(self, axis_num):
56405640
else:
56415641
raise ValueError('Axis must be 0 or 1 (got %r)' % axis_num)
56425642

5643-
def mode(self, axis=0, numeric_only=False):
5643+
def mode(self, axis=0, numeric_only=False, dropna=True):
56445644
"""
56455645
Gets the mode(s) of each element along the axis selected. Adds a row
56465646
for each mode per label, fills in gaps with nan.
@@ -5658,6 +5658,8 @@ def mode(self, axis=0, numeric_only=False):
56585658
* 1 or 'columns' : get mode of each row
56595659
numeric_only : boolean, default False
56605660
if True, only apply to numeric columns
5661+
dropna : boolean, default True
5662+
Don't include NaN values.
56615663
56625664
Returns
56635665
-------
@@ -5674,7 +5676,7 @@ def mode(self, axis=0, numeric_only=False):
56745676
data = self if not numeric_only else self._get_numeric_data()
56755677

56765678
def f(s):
5677-
return s.mode()
5679+
return s.mode(dropna=dropna)
56785680

56795681
return data.apply(f, axis=axis)
56805682

pandas/core/series.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1236,11 +1236,16 @@ def count(self, level=None):
12361236
return self._constructor(out, index=lev,
12371237
dtype='int64').__finalize__(self)
12381238

1239-
def mode(self):
1239+
def mode(self, dropna=True):
12401240
"""Return the mode(s) of the dataset.
12411241
12421242
Always returns Series even if only one value is returned.
12431243
1244+
Parameters
1245+
----------
1246+
dropna : boolean, default True
1247+
Don't include NaN values.
1248+
12441249
Returns
12451250
-------
12461251
modes : Series (sorted)

0 commit comments

Comments
 (0)