@@ -1657,7 +1657,7 @@ def test_index_label_overlaps_location():
16571657 expected = ser .take ([1 , 3 , 4 ])
16581658 tm .assert_series_equal (actual , expected )
16591659
1660- # ... and again, with a generic Index of floats
1660+ # and again, with a generic Index of floats
16611661 df .index = df .index .astype (float )
16621662 g = df .groupby (list ("ababb" ))
16631663 actual = g .filter (lambda x : len (x ) > 2 )
@@ -2322,3 +2322,23 @@ def test_groupby_empty_multi_column():
23222322 [], columns = ["C" ], index = MultiIndex ([[], []], [[], []], names = ["A" , "B" ])
23232323 )
23242324 tm .assert_frame_equal (result , expected )
2325+
2326+
2327+ def test_groupby_filtered_df_std ():
2328+ # GH 16174
2329+ dicts = [
2330+ {"filter_col" : False , "groupby_col" : True , "bool_col" : True , "float_col" : 10.5 },
2331+ {"filter_col" : True , "groupby_col" : True , "bool_col" : True , "float_col" : 20.5 },
2332+ {"filter_col" : True , "groupby_col" : True , "bool_col" : True , "float_col" : 30.5 },
2333+ ]
2334+ df = DataFrame (dicts )
2335+
2336+ df_filter = df [df ["filter_col" ] == True ] # noqa:E712
2337+ dfgb = df_filter .groupby ("groupby_col" )
2338+ result = dfgb .std ()
2339+ expected = DataFrame (
2340+ [[0.0 , 0.0 , 7.071068 ]],
2341+ columns = ["filter_col" , "bool_col" , "float_col" ],
2342+ index = Index ([True ], name = "groupby_col" ),
2343+ )
2344+ tm .assert_frame_equal (result , expected )
0 commit comments