@@ -26,30 +26,9 @@ def test_dict_args_val_error(dataframe):
26
26
dataframe .summarize ({"a" : 1 })
27
27
28
28
29
- @pytest .mark .functions
30
- def test_dict_nested_error (dataframe ):
31
- """
32
- Raise if func in nested dict
33
- is a wrong type
34
- """
35
- with pytest .raises (
36
- TypeError , match = "func in nested dictionary for a in argument 0.+"
37
- ):
38
- dataframe .summarize ({"a" : {"b" : 1 }})
39
-
40
-
41
29
func = lambda grp : grp .Revenue .sum () / grp .Quantity .sum () # noqa: E731
42
30
43
31
44
- @pytest .mark .functions
45
- def test_nested_dict_agg_error (dataframe ):
46
- """
47
- Raise if func triggers an attributeerror/valueerror
48
- """
49
- with pytest .raises (AttributeError ):
50
- dataframe .summarize ({"a" : {"b" : func }})
51
-
52
-
53
32
@pytest .mark .functions
54
33
def test_dict_agg_error (dataframe ):
55
34
"""
@@ -115,7 +94,12 @@ def test_tuple_func_seq_error(dataframe):
115
94
dataframe .summarize (("a" , [np .sum , 1 ], "name" ))
116
95
117
96
118
- args = [{"a" : "sum" }, ("a" , "sum" ), ("a" , np .sum ), {"a" : np .sum }]
97
+ args = [
98
+ {"a" : lambda df : df .a .sum ()},
99
+ ("a" , "sum" ),
100
+ ("a" , np .sum ),
101
+ {"a" : lambda f : np .sum (f .a )},
102
+ ]
119
103
120
104
121
105
@pytest .mark .parametrize ("test_input" , args )
@@ -127,54 +111,6 @@ def test_args_various(dataframe, test_input):
127
111
assert_frame_equal (expected , actual )
128
112
129
113
130
- args = [
131
- ({"a" : "sum" }, "decorated-elephant" ),
132
- ({"a" : np .sum }, "decorated-elephant" ),
133
- (("a" , "sum" ), "decorated-elephant" ),
134
- ]
135
-
136
-
137
- @pytest .mark .parametrize ("test_input,by" , args )
138
- @pytest .mark .functions
139
- def test_args_various_grouped (dataframe , test_input , by ):
140
- """Test output for various arguments"""
141
- expected = dataframe .groupby ("decorated-elephant" ).agg ({"a" : "sum" })
142
- actual = dataframe .summarize (test_input , by = by )
143
- assert_frame_equal (expected , actual )
144
-
145
-
146
- @pytest .mark .functions
147
- def test_dict_nested (dataframe ):
148
- """Test output for dict"""
149
- expected = (
150
- dataframe .agg ({"a" : ["sum" ]})
151
- .rename (columns = {"a" : "a_sum" })
152
- .reset_index (drop = True )
153
- )
154
- actual = dataframe .summarize ({"a" : {"a_sum" : "sum" }})
155
- assert_frame_equal (expected , actual )
156
-
157
-
158
- @pytest .mark .functions
159
- def test_dict_nested_grouped_str (dataframe ):
160
- """Test output for dict on a groupby"""
161
- expected = dataframe .groupby ("decorated-elephant" ).agg (a_sum = ("a" , "sum" ))
162
- actual = dataframe .summarize (
163
- {"a" : {"a_sum" : "sum" }}, by = "decorated-elephant"
164
- )
165
- assert_frame_equal (expected , actual )
166
-
167
-
168
- @pytest .mark .functions
169
- def test_dict_nested_grouped_callable (dataframe ):
170
- """Test output for dict on a groupby"""
171
- expected = dataframe .groupby ("decorated-elephant" ).agg (a_sum = ("a" , "sum" ))
172
- actual = dataframe .summarize (
173
- {"a" : {"a_sum" : np .sum }}, by = {"by" : "decorated-elephant" }
174
- )
175
- assert_frame_equal (expected , actual )
176
-
177
-
178
114
args = [("a" , "sum" , "{_col}_{_fn}" ), ("a" , np .sum , "{_col}_{_fn}" )]
179
115
180
116
@@ -231,7 +167,7 @@ def test_tuple_func_list_grouped_dupes(dataframe):
231
167
grp = dataframe .groupby ("decorated-elephant" )
232
168
expected = grp .agg (a_sum0 = ("a" , "sum" ), a_sum1 = ("a" , "sum" ))
233
169
actual = dataframe .summarize (
234
- ("a" , ["sum" , np .sum ], "{_col}_{_fn}" ), by = " decorated-elephant"
170
+ ("a" , ["sum" , np .sum ], "{_col}_{_fn}" ), by = { "by" : " decorated-elephant"}
235
171
)
236
172
assert_frame_equal (expected , actual )
237
173
0 commit comments