Skip to content

Commit f003185

Browse files
committed
Merge remote-tracking branch 'upstream/master' into as_index_false
2 parents 24ad221 + c3c4ccf commit f003185

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

pandas/tests/groupby/test_function.py

+22
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,28 @@ def test_ops_general(op, targop):
573573
tm.assert_frame_equal(result, expected)
574574

575575

576+
def test_ops_not_as_index(reduction_func):
577+
# GH 10355
578+
# Using as_index=False should not modify grouped column
579+
580+
if reduction_func in ("nth", "ngroup", "size",):
581+
pytest.skip("Skip until behavior is determined (GH #5755)")
582+
583+
if reduction_func in ("corrwith", "idxmax", "idxmin", "mad", "nunique", "skew",):
584+
pytest.xfail(
585+
"_GroupBy._python_apply_general incorrectly modifies grouping columns"
586+
)
587+
588+
df = DataFrame(np.random.randint(0, 5, size=(100, 2)), columns=["a", "b"])
589+
expected = getattr(df.groupby("a"), reduction_func)().reset_index()
590+
591+
result = getattr(df.groupby("a", as_index=False), reduction_func)()
592+
tm.assert_frame_equal(result, expected)
593+
594+
result = getattr(df.groupby("a", as_index=False)["b"], reduction_func)()
595+
tm.assert_frame_equal(result, expected)
596+
597+
576598
def test_max_nan_bug():
577599
raw = """,Date,app,File
578600
-04-23,2013-04-23 00:00:00,,log080001.log

0 commit comments

Comments
 (0)