Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
03ee26b
Added test coverage for observed=False with ops
WillAyd May 15, 2019
ee549ed
Fixed issue with observed=False and nth
WillAyd May 15, 2019
f0a510d
Stubbed whatsnew note
WillAyd May 15, 2019
f671204
Merge remote-tracking branch 'upstream/master' into nth-na-handling
WillAyd May 16, 2019
94dda01
Merge remote-tracking branch 'upstream/master' into nth-na-handling
WillAyd May 17, 2019
e59a991
lint fixup
WillAyd May 17, 2019
3677471
Simplified test
WillAyd May 19, 2019
34c2f06
Merge remote-tracking branch 'upstream/master' into nth-na-handling
WillAyd May 19, 2019
2ca34e3
whatsnew whitespace fix
WillAyd May 19, 2019
d3e5efa
Merge remote-tracking branch 'upstream/master' into nth-na-handling
WillAyd Jun 3, 2019
f9758b8
Merge remote-tracking branch 'upstream/master' into nth-na-handling
WillAyd Jun 4, 2019
ad729c5
Merge remote-tracking branch 'upstream/master' into nth-na-handling
WillAyd Jun 27, 2019
5b7b6bc
Merge remote-tracking branch 'upstream/master' into nth-na-handling
WillAyd Jul 15, 2019
aff7327
Merge remote-tracking branch 'upstream/master' into nth-na-handling
WillAyd Jul 15, 2019
47201fb
blackify
WillAyd Jul 15, 2019
56822cc
Merge remote-tracking branch 'upstream/master' into nth-na-handling
WillAyd Jul 15, 2019
1804e27
Removed doc whitespace
WillAyd Jul 15, 2019
4c2e413
Merge remote-tracking branch 'upstream/master' into nth-na-handling
WillAyd Jul 25, 2019
a837564
moved whatsnew to 0.25.1
WillAyd Jul 25, 2019
308e569
Merge remote-tracking branch 'upstream/master' into WillAyd-nth-na-ha…
TomAugspurger Aug 19, 2019
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
Next Next commit
Added test coverage for observed=False with ops
  • Loading branch information
WillAyd committed May 15, 2019
commit 03ee26b5d18b8b459e1f27f32d92026e3456eaac
7 changes: 7 additions & 0 deletions pandas/tests/groupby/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,10 @@ def three_group():
'D': np.random.randn(11),
'E': np.random.randn(11),
'F': np.random.randn(11)})


AGG_FUNCS = ['sum', 'prod', 'min', 'max', 'mean', 'median', 'var', 'first',
'last', 'nth'] # TODO: ohlc?
@pytest.fixture(params=AGG_FUNCS)
def agg_func(request):
return request.param
29 changes: 29 additions & 0 deletions pandas/tests/groupby/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,35 @@ def test_observed_groups_with_nan(observed):
tm.assert_dict_equal(result, expected)


def test_observed_ops(agg_func):
cat = pd.Categorical(['a', np.nan, np.nan], categories=['a', 'b', 'c'])
ser = pd.Series([1., 2., 3.])
df = pd.DataFrame({'cat': cat, 'ser': ser})

grp = df.groupby('cat', observed=False)['ser']
func = getattr(grp, agg_func)

if agg_func == 'nth': # Need an argument
result = func(0)
else:
result = func()

if agg_func == 'sum': # TODO: maybe a bug?
expected_vals = [1., 0., 0.]
elif agg_func == 'prod': # TODO: Definitely seems like a bug
expected_vals = [1., 1., 1.]
elif agg_func == 'var':
expected_vals = [np.nan, np.nan, np.nan]
else:
expected_vals = [1., np.nan, np.nan]

index = pd.Categorical(['a', 'b', 'c'], categories=['a', 'b', 'c'])
expected = pd.Series(expected_vals, index=index, name='ser')
expected.index.name = 'cat'

tm.assert_series_equal(result, expected)


def test_dataframe_categorical_with_nan(observed):
# GH 21151
s1 = pd.Categorical([np.nan, 'a', np.nan, 'a'],
Expand Down