Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added tests for all implementation
  • Loading branch information
WillAyd committed Feb 28, 2018
commit 2ad0b50fdc7a9fd51b04e1724b09b8c9909ece10
32 changes: 20 additions & 12 deletions pandas/tests/groupby/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -2117,25 +2117,33 @@ def interweave(list_obj):
exp = DataFrame({'key': keys, 'val': _exp_vals})
assert_frame_equal(result, exp)

@pytest.mark.parametrize("agg_func", ['any', 'all'])
@pytest.mark.parametrize("skipna", [True, False])
@pytest.mark.parametrize("vals,exp", [
(['foo', 'bar', 'baz'], True), (['foo', '', ''], True),
(['', '', ''], False), ([1, 2, 3], True), ([1, 0, 0], True),
([0, 0, 0], False), ([1., 2., 3.], True), ([1., 0., 0.], True),
([0., 0., 0.], False), ([True, True, True], True),
([True, False, False], True), ([False, False, False], False),
([np.nan, np.nan, np.nan], False)
@pytest.mark.parametrize("vals", [
['foo', 'bar', 'baz'], ['foo', '', ''], ['', '', ''],
[1, 2, 3], [1, 0, 0], [0, 0, 0],
[1., 2., 3.], [1., 0., 0.], [0., 0., 0.],
[True, True, True], [True, False, False], [False, False, False],
[np.nan, np.nan, np.nan]
])
def test_groupby_any(self, skipna, vals, exp):
def test_groupby_bool_aggs(self, agg_func, skipna, vals):
df = DataFrame({'key': ['a'] * 3 + ['b'] * 3, 'val': vals * 2})

# edge case for missing data with skipna=False
if not(skipna) and all(isna(vals)):
exp = True
if compat.PY3:
import builtins as bltins
else:
import __builtins__ as bltins

# Figure out expectation using Python builtin
exp = getattr(bltins, agg_func)(vals)

# edge case for missing data with skipna and 'any'
if skipna and all(isna(vals)) and agg_func=='any':
exp = False

exp_df = DataFrame([exp] * 2, columns=['val'], index=pd.Index(
['a', 'b'], name='key'))
result = df.groupby('key').any(skipna=skipna)
result = getattr(df.groupby('key'), agg_func)(skipna=skipna)
assert_frame_equal(result, exp_df)

def test_dont_clobber_name_column(self):
Expand Down