@@ -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 )
@@ -2283,3 +2283,23 @@ def test_groupby_empty_multi_column():
2283
2283
[], columns = ["C" ], index = MultiIndex ([[], []], [[], []], names = ["A" , "B" ])
2284
2284
)
2285
2285
tm .assert_frame_equal (result , expected )
2286
+
2287
+
2288
+ def test_groupby_filtered_df_std ():
2289
+ # GH 16174
2290
+ dicts = [
2291
+ {"filter_col" : False , "groupby_col" : True , "bool_col" : True , "float_col" : 10.5 },
2292
+ {"filter_col" : True , "groupby_col" : True , "bool_col" : True , "float_col" : 20.5 },
2293
+ {"filter_col" : True , "groupby_col" : True , "bool_col" : True , "float_col" : 30.5 },
2294
+ ]
2295
+ df = DataFrame (dicts )
2296
+
2297
+ df_filter = df [df ["filter_col" ] == True ] # noqa:E712
2298
+ dfgb = df_filter .groupby ("groupby_col" )
2299
+ result = dfgb .std ()
2300
+ expected = DataFrame (
2301
+ [[0.0 , 0.0 , 7.071068 ]],
2302
+ columns = ["filter_col" , "bool_col" , "float_col" ],
2303
+ index = Index ([True ], name = "groupby_col" ),
2304
+ )
2305
+ tm .assert_frame_equal (result , expected )
0 commit comments