|
21 | 21 | )
|
22 | 22 | import pandas._testing as tm
|
23 | 23 | from pandas.core.groupby.base import maybe_normalize_deprecated_kernels
|
24 |
| -from pandas.core.groupby.generic import ( |
25 |
| - DataFrameGroupBy, |
26 |
| - SeriesGroupBy, |
27 |
| -) |
| 24 | +from pandas.core.groupby.generic import DataFrameGroupBy |
28 | 25 |
|
29 | 26 |
|
30 | 27 | def assert_fp_equal(a, b):
|
@@ -195,10 +192,8 @@ def test_transform_axis_1_reducer(request, reduction_func):
|
195 | 192 | # GH#45715
|
196 | 193 | if reduction_func in (
|
197 | 194 | "corrwith",
|
198 |
| - "first", |
199 | 195 | "idxmax",
|
200 | 196 | "idxmin",
|
201 |
| - "last", |
202 | 197 | "ngroup",
|
203 | 198 | "nth",
|
204 | 199 | ):
|
@@ -418,45 +413,36 @@ def test_transform_select_columns(df):
|
418 | 413 | tm.assert_frame_equal(result, expected)
|
419 | 414 |
|
420 | 415 |
|
421 |
| -@pytest.mark.parametrize("duplicates", [True, False]) |
422 |
| -def test_transform_exclude_nuisance(df, duplicates): |
| 416 | +def test_transform_exclude_nuisance(df): |
423 | 417 | # case that goes through _transform_item_by_item
|
424 | 418 |
|
425 |
| - if duplicates: |
426 |
| - # make sure we work with duplicate columns GH#41427 |
427 |
| - df.columns = ["A", "C", "C", "D"] |
| 419 | + df.columns = ["A", "B", "B", "D"] |
428 | 420 |
|
429 | 421 | # this also tests orderings in transform between
|
430 | 422 | # series/frame to make sure it's consistent
|
431 | 423 | expected = {}
|
432 | 424 | grouped = df.groupby("A")
|
433 | 425 |
|
434 |
| - gbc = grouped["C"] |
435 |
| - warn = FutureWarning if duplicates else None |
436 |
| - with tm.assert_produces_warning(warn, match="Dropping invalid columns"): |
437 |
| - expected["C"] = gbc.transform(np.mean) |
438 |
| - if duplicates: |
439 |
| - # squeeze 1-column DataFrame down to Series |
440 |
| - expected["C"] = expected["C"]["C"] |
| 426 | + gbc = grouped["B"] |
| 427 | + with tm.assert_produces_warning(FutureWarning, match="Dropping invalid columns"): |
| 428 | + expected["B"] = gbc.transform(lambda x: np.mean(x)) |
| 429 | + # squeeze 1-column DataFrame down to Series |
| 430 | + expected["B"] = expected["B"]["B"] |
441 | 431 |
|
442 |
| - assert isinstance(gbc.obj, DataFrame) |
443 |
| - assert isinstance(gbc, DataFrameGroupBy) |
444 |
| - else: |
445 |
| - assert isinstance(gbc, SeriesGroupBy) |
446 |
| - assert isinstance(gbc.obj, Series) |
| 432 | + assert isinstance(gbc.obj, DataFrame) |
| 433 | + assert isinstance(gbc, DataFrameGroupBy) |
447 | 434 |
|
448 | 435 | expected["D"] = grouped["D"].transform(np.mean)
|
449 | 436 | expected = DataFrame(expected)
|
450 | 437 | with tm.assert_produces_warning(FutureWarning, match="Dropping invalid columns"):
|
451 |
| - result = df.groupby("A").transform(np.mean) |
| 438 | + result = df.groupby("A").transform(lambda x: np.mean(x)) |
452 | 439 |
|
453 | 440 | tm.assert_frame_equal(result, expected)
|
454 | 441 |
|
455 | 442 |
|
456 | 443 | def test_transform_function_aliases(df):
|
457 |
| - with tm.assert_produces_warning(FutureWarning, match="Dropping invalid columns"): |
458 |
| - result = df.groupby("A").transform("mean") |
459 |
| - expected = df.groupby("A").transform(np.mean) |
| 444 | + result = df.groupby("A").transform("mean") |
| 445 | + expected = df.groupby("A").transform(np.mean) |
460 | 446 | tm.assert_frame_equal(result, expected)
|
461 | 447 |
|
462 | 448 | result = df.groupby("A")["C"].transform("mean")
|
|
0 commit comments