Skip to content

Commit b922fb4

Browse files
author
Moi
committed
test changes
1 parent a54a052 commit b922fb4

File tree

1 file changed

+16
-26
lines changed

1 file changed

+16
-26
lines changed

pandas/tests/groupby/aggregate/test_aggregate.py

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,10 @@ def test_multi_function_flexible_mix(df):
287287
result = grouped.aggregate(d)
288288
tm.assert_frame_equal(result, expected)
289289

290-
290+
@pytest.mark.parametrize('as_index', [True, False])
291291
def test_not_as_index_agg_list():
292292

293293
# GH 25011
294-
# expected behavhior of agg with as_index=True
295-
as_index = False
296294
array = [[3, 1, 2],
297295
[3, 3, 4],
298296
[4, 5, 6],
@@ -301,31 +299,23 @@ def test_not_as_index_agg_list():
301299
groupby = df.groupby('shouldnt_be_index', as_index=as_index)
302300
result = groupby.agg(['min', 'max'])
303301

304-
array2 = [[3, 1, 3, 2, 4],
305-
[4, 5, 7, 6, 8]]
306-
columns = pd.MultiIndex(levels=[['A', 'B', 'shouldnt_be_index'],
307-
['min', 'max', '']],
308-
codes=[[2, 0, 0, 1, 1], [2, 0, 1, 0, 1]])
309-
expected = pd.DataFrame(array2, columns=columns)
302+
if as_index:
310303

311-
tm.assert_frame_equal(result, expected)
304+
array2 = [[1, 3, 2, 4],
305+
[5, 7, 6, 8]]
306+
columns = pd.MultiIndex(levels=[['A', 'B'],
307+
['min', 'max']],
308+
codes=[[0, 0, 1, 1], [0, 1, 0, 1]])
309+
index = pd.Series([3, 4], name='should_be_index')
310+
expected = pd.DataFrame(array2, columns=columns, index=index)
312311

313-
# expected behavhior of agg with as_index=True
314-
as_index = True
315-
array = [[3, 1, 2],
316-
[3, 3, 4],
317-
[4, 5, 6],
318-
[4, 7, 8]]
319-
df = pd.DataFrame(array, columns=['should_be_index', 'A', 'B'])
320-
groupby = df.groupby('should_be_index', as_index=as_index)
321-
result = groupby.agg(['min', 'max'])
312+
else:
322313

323-
array2 = [[1, 3, 2, 4],
324-
[5, 7, 6, 8]]
325-
columns = pd.MultiIndex(levels=[['A', 'B'],
326-
['min', 'max']],
327-
codes=[[0, 0, 1, 1], [0, 1, 0, 1]])
328-
index = pd.Series([3, 4], name='should_be_index')
329-
expected = pd.DataFrame(array2, columns=columns, index=index)
314+
array2 = [[3, 1, 3, 2, 4],
315+
[4, 5, 7, 6, 8]]
316+
columns = pd.MultiIndex(levels=[['A', 'B', 'shouldnt_be_index'],
317+
['min', 'max', '']],
318+
codes=[[2, 0, 0, 1, 1], [2, 0, 1, 0, 1]])
319+
expected = pd.DataFrame(array2, columns=columns)
330320

331321
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)