Skip to content

Commit f11fcb1

Browse files
committed
MAINT: Use pytest idiom for added tests
1 parent f0a449e commit f11fcb1

File tree

1 file changed

+21
-40
lines changed

1 file changed

+21
-40
lines changed

pandas/tests/groupby/aggregate/test_aggregate.py

Lines changed: 21 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -494,51 +494,32 @@ def test_mangled(self):
494494
)
495495
tm.assert_frame_equal(result, expected)
496496

497-
def test_lambda_named_agg(self):
498-
# see gh-28467
499-
animals = DataFrame(
500-
{
501-
"kind": ["cat", "dog", "cat", "dog"],
502-
"height": [9.1, 6.0, 9.5, 34.0],
503-
"weight": [7.9, 7.5, 9.9, 198.0],
504-
}
505-
)
506497

507-
result = animals.groupby("kind").agg(
508-
mean_height=("height", "mean"),
509-
perc90=("height", lambda s: np.percentile(s, q=0.90)),
510-
)
511-
expected = DataFrame(
512-
[[9.3, 9.1036], [20.0, 6.252]],
513-
columns=["mean_height", "perc90"],
514-
index=Index(["cat", "dog"], name="kind"),
515-
)
516-
517-
tm.assert_frame_equal(result, expected)
498+
def myfunc(s):
499+
return np.percentile(s, q=0.90)
518500

519-
def test_func_named_agg(self):
520-
# see gh-28467
521-
def myfunc(s):
522-
return np.percentile(s, q=0.90)
523501

524-
animals = DataFrame(
525-
{
526-
"kind": ["cat", "dog", "cat", "dog"],
527-
"height": [9.1, 6.0, 9.5, 34.0],
528-
"weight": [7.9, 7.5, 9.9, 198.0],
529-
}
530-
)
502+
@pytest.mark.parametrize("func", [lambda s: np.percentile(s, q=0.90), myfunc])
503+
def test_lambda_named_agg(func):
504+
# see gh-28467
505+
animals = DataFrame(
506+
{
507+
"kind": ["cat", "dog", "cat", "dog"],
508+
"height": [9.1, 6.0, 9.5, 34.0],
509+
"weight": [7.9, 7.5, 9.9, 198.0],
510+
}
511+
)
531512

532-
result = animals.groupby("kind").agg(
533-
mean_height=("height", "mean"), perc90=("height", myfunc)
534-
)
535-
expected = DataFrame(
536-
[[9.3, 9.1036], [20.0, 6.252]],
537-
columns=["mean_height", "perc90"],
538-
index=Index(["cat", "dog"], name="kind"),
539-
)
513+
result = animals.groupby("kind").agg(
514+
mean_height=("height", "mean"), perc90=("height", func)
515+
)
516+
expected = DataFrame(
517+
[[9.3, 9.1036], [20.0, 6.252]],
518+
columns=["mean_height", "perc90"],
519+
index=Index(["cat", "dog"], name="kind"),
520+
)
540521

541-
tm.assert_frame_equal(result, expected)
522+
tm.assert_frame_equal(result, expected)
542523

543524

544525
class TestLambdaMangling:

0 commit comments

Comments
 (0)