@@ -1316,6 +1316,40 @@ def test_quantile_raises():
13161316 df .groupby ("key" ).quantile ()
13171317
13181318
1319+ def test_quantile_out_of_bounds_q_raises ():
1320+ # https://github.com/pandas-dev/pandas/issues/27470
1321+ df = pd .DataFrame (dict (a = [0 , 0 , 0 , 1 , 1 , 1 ], b = range (6 )))
1322+ g = df .groupby ([0 , 0 , 0 , 1 , 1 , 1 ])
1323+ with pytest .raises (ValueError , match = "Got '50.0' instead" ):
1324+ g .quantile (50 )
1325+
1326+ with pytest .raises (ValueError , match = "Got '-1.0' instead" ):
1327+ g .quantile (- 1 )
1328+
1329+
1330+ def test_quantile_missing_group_values_no_segfaults ():
1331+ # GH 28662
1332+ data = np .array ([1.0 , np .nan , 1.0 ])
1333+ df = pd .DataFrame (dict (key = data , val = range (3 )))
1334+
1335+ # Random segfaults; would have been guaranteed in loop
1336+ grp = df .groupby ("key" )
1337+ for _ in range (100 ):
1338+ grp .quantile ()
1339+
1340+
1341+ def test_quantile_missing_group_values_correct_results ():
1342+ # GH 28662
1343+ data = np .array ([1.0 , np .nan , 3.0 , np .nan ])
1344+ df = pd .DataFrame (dict (key = data , val = range (4 )))
1345+
1346+ result = df .groupby ("key" ).quantile ()
1347+ expected = pd .DataFrame (
1348+ [1.0 , 3.0 ], index = pd .Index ([1.0 , 3.0 ], name = "key" ), columns = ["val" ]
1349+ )
1350+ tm .assert_frame_equal (result , expected )
1351+
1352+
13191353# pipe
13201354# --------------------------------
13211355
0 commit comments