|
1 | 1 | """ |
2 | | -test methods relating to generic function evaluation |
3 | | -the so-called white/black lists |
| 2 | +TODO: Existing tests should be moved or deduplicated |
| 3 | +Do not add tests here! |
4 | 4 | """ |
5 | 5 |
|
6 | 6 | from string import ascii_lowercase |
|
14 | 14 | date_range, |
15 | 15 | ) |
16 | 16 | import pandas._testing as tm |
17 | | -from pandas.core.groupby.base import ( |
18 | | - groupby_other_methods, |
19 | | - reduction_kernels, |
20 | | - transformation_kernels, |
21 | | -) |
22 | 17 |
|
23 | 18 | AGG_FUNCTIONS = [ |
24 | 19 | "sum", |
@@ -100,131 +95,6 @@ def test_regression_allowlist_methods(raw_frame, op, axis, skipna, sort): |
100 | 95 | tm.assert_frame_equal(result, expected) |
101 | 96 |
|
102 | 97 |
|
103 | | -def test_groupby_blocklist(df_letters): |
104 | | - df = df_letters |
105 | | - s = df_letters.floats |
106 | | - |
107 | | - blocklist = [ |
108 | | - "eval", |
109 | | - "query", |
110 | | - "abs", |
111 | | - "where", |
112 | | - "mask", |
113 | | - "align", |
114 | | - "groupby", |
115 | | - "clip", |
116 | | - "astype", |
117 | | - "at", |
118 | | - "combine", |
119 | | - "consolidate", |
120 | | - "convert_objects", |
121 | | - ] |
122 | | - to_methods = [method for method in dir(df) if method.startswith("to_")] |
123 | | - |
124 | | - blocklist.extend(to_methods) |
125 | | - |
126 | | - for bl in blocklist: |
127 | | - for obj in (df, s): |
128 | | - gb = obj.groupby(df.letters) |
129 | | - |
130 | | - # e.g., to_csv |
131 | | - defined_but_not_allowed = ( |
132 | | - f"(?:^Cannot.+{repr(bl)}.+'{type(gb).__name__}'.+try " |
133 | | - f"using the 'apply' method$)" |
134 | | - ) |
135 | | - |
136 | | - # e.g., query, eval |
137 | | - not_defined = ( |
138 | | - f"(?:^'{type(gb).__name__}' object has no attribute {repr(bl)}$)" |
139 | | - ) |
140 | | - |
141 | | - msg = f"{defined_but_not_allowed}|{not_defined}" |
142 | | - |
143 | | - with pytest.raises(AttributeError, match=msg): |
144 | | - getattr(gb, bl) |
145 | | - |
146 | | - |
147 | | -def test_tab_completion(mframe): |
148 | | - grp = mframe.groupby(level="second") |
149 | | - results = {v for v in dir(grp) if not v.startswith("_")} |
150 | | - expected = { |
151 | | - "A", |
152 | | - "B", |
153 | | - "C", |
154 | | - "agg", |
155 | | - "aggregate", |
156 | | - "apply", |
157 | | - "boxplot", |
158 | | - "filter", |
159 | | - "first", |
160 | | - "get_group", |
161 | | - "groups", |
162 | | - "hist", |
163 | | - "indices", |
164 | | - "last", |
165 | | - "max", |
166 | | - "mean", |
167 | | - "median", |
168 | | - "min", |
169 | | - "ngroups", |
170 | | - "nth", |
171 | | - "ohlc", |
172 | | - "plot", |
173 | | - "prod", |
174 | | - "size", |
175 | | - "std", |
176 | | - "sum", |
177 | | - "transform", |
178 | | - "var", |
179 | | - "sem", |
180 | | - "count", |
181 | | - "nunique", |
182 | | - "head", |
183 | | - "describe", |
184 | | - "cummax", |
185 | | - "quantile", |
186 | | - "rank", |
187 | | - "cumprod", |
188 | | - "tail", |
189 | | - "resample", |
190 | | - "cummin", |
191 | | - "fillna", |
192 | | - "cumsum", |
193 | | - "cumcount", |
194 | | - "ngroup", |
195 | | - "all", |
196 | | - "shift", |
197 | | - "skew", |
198 | | - "take", |
199 | | - "pct_change", |
200 | | - "any", |
201 | | - "corr", |
202 | | - "corrwith", |
203 | | - "cov", |
204 | | - "dtypes", |
205 | | - "ndim", |
206 | | - "diff", |
207 | | - "idxmax", |
208 | | - "idxmin", |
209 | | - "ffill", |
210 | | - "bfill", |
211 | | - "rolling", |
212 | | - "expanding", |
213 | | - "pipe", |
214 | | - "sample", |
215 | | - "ewm", |
216 | | - "value_counts", |
217 | | - } |
218 | | - assert results == expected |
219 | | - |
220 | | - |
221 | | -def test_groupby_function_rename(mframe): |
222 | | - grp = mframe.groupby(level="second") |
223 | | - for name in ["sum", "prod", "min", "max", "first", "last"]: |
224 | | - f = getattr(grp, name) |
225 | | - assert f.__name__ == name |
226 | | - |
227 | | - |
228 | 98 | @pytest.mark.parametrize( |
229 | 99 | "method", |
230 | 100 | [ |
@@ -285,47 +155,3 @@ def test_groupby_selection_other_methods(df): |
285 | 155 | tm.assert_frame_equal( |
286 | 156 | g.filter(lambda x: len(x) == 3), g_exp.filter(lambda x: len(x) == 3) |
287 | 157 | ) |
288 | | - |
289 | | - |
290 | | -def test_all_methods_categorized(mframe): |
291 | | - grp = mframe.groupby(mframe.iloc[:, 0]) |
292 | | - names = {_ for _ in dir(grp) if not _.startswith("_")} - set(mframe.columns) |
293 | | - new_names = set(names) |
294 | | - new_names -= reduction_kernels |
295 | | - new_names -= transformation_kernels |
296 | | - new_names -= groupby_other_methods |
297 | | - |
298 | | - assert not reduction_kernels & transformation_kernels |
299 | | - assert not reduction_kernels & groupby_other_methods |
300 | | - assert not transformation_kernels & groupby_other_methods |
301 | | - |
302 | | - # new public method? |
303 | | - if new_names: |
304 | | - msg = f""" |
305 | | -There are uncategorized methods defined on the Grouper class: |
306 | | -{new_names}. |
307 | | -
|
308 | | -Was a new method recently added? |
309 | | -
|
310 | | -Every public method On Grouper must appear in exactly one the |
311 | | -following three lists defined in pandas.core.groupby.base: |
312 | | -- `reduction_kernels` |
313 | | -- `transformation_kernels` |
314 | | -- `groupby_other_methods` |
315 | | -see the comments in pandas/core/groupby/base.py for guidance on |
316 | | -how to fix this test. |
317 | | - """ |
318 | | - raise AssertionError(msg) |
319 | | - |
320 | | - # removed a public method? |
321 | | - all_categorized = reduction_kernels | transformation_kernels | groupby_other_methods |
322 | | - if names != all_categorized: |
323 | | - msg = f""" |
324 | | -Some methods which are supposed to be on the Grouper class |
325 | | -are missing: |
326 | | -{all_categorized - names}. |
327 | | -
|
328 | | -They're still defined in one of the lists that live in pandas/core/groupby/base.py. |
329 | | -If you removed a method, you should update them |
330 | | -""" |
331 | | - raise AssertionError(msg) |
0 commit comments