@@ -2117,25 +2117,33 @@ def interweave(list_obj):
21172117 exp = DataFrame ({'key' : keys , 'val' : _exp_vals })
21182118 assert_frame_equal (result , exp )
21192119
2120+ @pytest .mark .parametrize ("agg_func" , ['any' , 'all' ])
21202121 @pytest .mark .parametrize ("skipna" , [True , False ])
2121- @pytest .mark .parametrize ("vals,exp" , [
2122- (['foo' , 'bar' , 'baz' ], True ), (['foo' , '' , '' ], True ),
2123- (['' , '' , '' ], False ), ([1 , 2 , 3 ], True ), ([1 , 0 , 0 ], True ),
2124- ([0 , 0 , 0 ], False ), ([1. , 2. , 3. ], True ), ([1. , 0. , 0. ], True ),
2125- ([0. , 0. , 0. ], False ), ([True , True , True ], True ),
2126- ([True , False , False ], True ), ([False , False , False ], False ),
2127- ([np .nan , np .nan , np .nan ], False )
2122+ @pytest .mark .parametrize ("vals" , [
2123+ ['foo' , 'bar' , 'baz' ], ['foo' , '' , '' ], ['' , '' , '' ],
2124+ [1 , 2 , 3 ], [1 , 0 , 0 ], [0 , 0 , 0 ],
2125+ [1. , 2. , 3. ], [1. , 0. , 0. ], [0. , 0. , 0. ],
2126+ [True , True , True ], [True , False , False ], [False , False , False ],
2127+ [np .nan , np .nan , np .nan ]
21282128 ])
2129- def test_groupby_any (self , skipna , vals , exp ):
2129+ def test_groupby_bool_aggs (self , agg_func , skipna , vals ):
21302130 df = DataFrame ({'key' : ['a' ] * 3 + ['b' ] * 3 , 'val' : vals * 2 })
21312131
2132- # edge case for missing data with skipna=False
2133- if not (skipna ) and all (isna (vals )):
2134- exp = True
2132+ if compat .PY3 :
2133+ import builtins as bltins
2134+ else :
2135+ import __builtins__ as bltins
2136+
2137+ # Figure out expectation using Python builtin
2138+ exp = getattr (bltins , agg_func )(vals )
2139+
2140+ # edge case for missing data with skipna and 'any'
2141+ if skipna and all (isna (vals )) and agg_func == 'any' :
2142+ exp = False
21352143
21362144 exp_df = DataFrame ([exp ] * 2 , columns = ['val' ], index = pd .Index (
21372145 ['a' , 'b' ], name = 'key' ))
2138- result = df .groupby ('key' ). any (skipna = skipna )
2146+ result = getattr ( df .groupby ('key' ), agg_func ) (skipna = skipna )
21392147 assert_frame_equal (result , exp_df )
21402148
21412149 def test_dont_clobber_name_column (self ):
0 commit comments