3
3
Do not add tests here!
4
4
"""
5
5
6
- from string import ascii_lowercase
7
-
8
- import numpy as np
9
6
import pytest
10
7
11
8
from pandas import (
12
9
DataFrame ,
13
- Series ,
14
10
date_range ,
15
11
)
16
12
import pandas ._testing as tm
17
13
18
- AGG_FUNCTIONS = [
19
- "sum" ,
20
- "prod" ,
21
- "min" ,
22
- "max" ,
23
- "median" ,
24
- "mean" ,
25
- "skew" ,
26
- "std" ,
27
- "var" ,
28
- "sem" ,
29
- ]
30
- AGG_FUNCTIONS_WITH_SKIPNA = ["skew" ]
31
-
32
-
33
- @pytest .fixture
34
- def df ():
35
- return DataFrame (
36
- {
37
- "A" : ["foo" , "bar" , "foo" , "bar" , "foo" , "bar" , "foo" , "foo" ],
38
- "B" : ["one" , "one" , "two" , "three" , "two" , "two" , "one" , "three" ],
39
- "C" : np .random .randn (8 ),
40
- "D" : np .random .randn (8 ),
41
- }
42
- )
43
-
44
-
45
- @pytest .fixture
46
- def df_letters ():
47
- letters = np .array (list (ascii_lowercase ))
48
- N = 10
49
- random_letters = letters .take (np .random .randint (0 , 26 , N ))
50
- df = DataFrame (
51
- {
52
- "floats" : N / 10 * Series (np .random .random (N )),
53
- "letters" : Series (random_letters ),
54
- }
55
- )
56
- return df
57
-
58
14
59
- @pytest .fixture
60
- def raw_frame ():
61
- return DataFrame ([0 ])
62
-
63
-
64
- @pytest .mark .parametrize ("op" , AGG_FUNCTIONS )
15
+ @pytest .mark .parametrize (
16
+ "op" ,
17
+ [
18
+ "sum" ,
19
+ "prod" ,
20
+ "min" ,
21
+ "max" ,
22
+ "median" ,
23
+ "mean" ,
24
+ "skew" ,
25
+ "std" ,
26
+ "var" ,
27
+ "sem" ,
28
+ ],
29
+ )
65
30
@pytest .mark .parametrize ("axis" , [0 , 1 ])
66
31
@pytest .mark .parametrize ("skipna" , [True , False ])
67
32
@pytest .mark .parametrize ("sort" , [True , False ])
68
- def test_regression_allowlist_methods (raw_frame , op , axis , skipna , sort ):
33
+ def test_regression_allowlist_methods (op , axis , skipna , sort ):
69
34
# GH6944
70
35
# GH 17537
71
36
# explicitly test the allowlist methods
37
+ raw_frame = DataFrame ([0 ])
72
38
if axis == 0 :
73
39
frame = raw_frame
74
40
msg = "The 'axis' keyword in DataFrame.groupby is deprecated and will be"
@@ -79,7 +45,8 @@ def test_regression_allowlist_methods(raw_frame, op, axis, skipna, sort):
79
45
with tm .assert_produces_warning (FutureWarning , match = msg ):
80
46
grouped = frame .groupby (level = 0 , axis = axis , sort = sort )
81
47
82
- if op in AGG_FUNCTIONS_WITH_SKIPNA :
48
+ if op == "skew" :
49
+ # skew has skipna
83
50
result = getattr (grouped , op )(skipna = skipna )
84
51
expected = frame .groupby (level = 0 ).apply (
85
52
lambda h : getattr (h , op )(axis = axis , skipna = skipna )
0 commit comments