@@ -1657,7 +1657,7 @@ def test_index_label_overlaps_location():
1657
1657
expected = ser .take ([1 , 3 , 4 ])
1658
1658
tm .assert_series_equal (actual , expected )
1659
1659
1660
- # ... and again, with a generic Index of floats
1660
+ # and again, with a generic Index of floats
1661
1661
df .index = df .index .astype (float )
1662
1662
g = df .groupby (list ("ababb" ))
1663
1663
actual = g .filter (lambda x : len (x ) > 2 )
@@ -2322,3 +2322,23 @@ def test_groupby_empty_multi_column():
2322
2322
[], columns = ["C" ], index = MultiIndex ([[], []], [[], []], names = ["A" , "B" ])
2323
2323
)
2324
2324
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