Skip to content

Commit

Permalink
Remove test_apply_mutate.py
Browse files Browse the repository at this point in the history
  • Loading branch information
rhshadrach committed Dec 31, 2024
1 parent a8a84c8 commit 7bbc164
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 65 deletions.
50 changes: 50 additions & 0 deletions pandas/tests/groupby/test_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,22 @@ def fast(group):
tm.assert_frame_equal(fast_df, slow_df)


def test_apply_fast_slow_identical_index():
# GH#44803
df = DataFrame(
{
"name": ["Alice", "Bob", "Carl"],
"age": [20, 21, 20],
}
).set_index("name")

grp_by_same_value = df.groupby(["age"], group_keys=False).apply(lambda group: group)
grp_by_copy = df.groupby(["age"], group_keys=False).apply(
lambda group: group.copy()
)
tm.assert_frame_equal(grp_by_same_value, grp_by_copy)


@pytest.mark.parametrize(
"func",
[
Expand Down Expand Up @@ -1463,3 +1479,37 @@ def f_4(grp):
e.loc["Pony"] = np.nan
e.name = None
tm.assert_series_equal(result, e)


def test_nonreducer_nonstransform():
# GH3380, GH60619
# Was originally testing mutating in a UDF; now kept as an example
# of using apply with a nonreducer and nontransformer.
df = DataFrame(
{
"cat1": ["a"] * 8 + ["b"] * 6,
"cat2": ["c"] * 2
+ ["d"] * 2
+ ["e"] * 2
+ ["f"] * 2
+ ["c"] * 2
+ ["d"] * 2
+ ["e"] * 2,
"val": np.random.default_rng(2).integers(100, size=14),
}
)

def f(x):
x = x.copy()
x["rank"] = x.val.rank(method="min")
return x.groupby("cat2")["rank"].min()

expected = DataFrame(
{
"cat1": list("aaaabbb"),
"cat2": list("cdefcde"),
"rank": [3.0, 2.0, 5.0, 1.0, 2.0, 4.0, 1.0],
}
).set_index(["cat1", "cat2"])["rank"]
result = df.groupby("cat1").apply(f)
tm.assert_series_equal(result, expected)
65 changes: 0 additions & 65 deletions pandas/tests/groupby/test_apply_mutate.py

This file was deleted.

0 comments on commit 7bbc164

Please sign in to comment.