@@ -2117,25 +2117,33 @@ def interweave(list_obj):
2117
2117
exp = DataFrame ({'key' : keys , 'val' : _exp_vals })
2118
2118
assert_frame_equal (result , exp )
2119
2119
2120
+ @pytest .mark .parametrize ("agg_func" , ['any' , 'all' ])
2120
2121
@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 ]
2128
2128
])
2129
- def test_groupby_any (self , skipna , vals , exp ):
2129
+ def test_groupby_bool_aggs (self , agg_func , skipna , vals ):
2130
2130
df = DataFrame ({'key' : ['a' ] * 3 + ['b' ] * 3 , 'val' : vals * 2 })
2131
2131
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
2135
2143
2136
2144
exp_df = DataFrame ([exp ] * 2 , columns = ['val' ], index = pd .Index (
2137
2145
['a' , 'b' ], name = 'key' ))
2138
- result = df .groupby ('key' ). any (skipna = skipna )
2146
+ result = getattr ( df .groupby ('key' ), agg_func ) (skipna = skipna )
2139
2147
assert_frame_equal (result , exp_df )
2140
2148
2141
2149
def test_dont_clobber_name_column (self ):
0 commit comments