Skip to content

Commit a7cbaf6

Browse files
committed
TST: split test_groupby.py
closes #20696
1 parent 0d199e4 commit a7cbaf6

13 files changed

+5983
-5888
lines changed

pandas/tests/groupby/aggregate/test_aggregate.py

+26-45
Original file line numberDiff line numberDiff line change
@@ -15,51 +15,6 @@
1515
import pandas.util.testing as tm
1616

1717

18-
@pytest.fixture
19-
def ts():
20-
return tm.makeTimeSeries()
21-
22-
23-
@pytest.fixture
24-
def tsframe():
25-
return DataFrame(tm.getTimeSeriesData())
26-
27-
28-
@pytest.fixture
29-
def df():
30-
return DataFrame(
31-
{'A': ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'],
32-
'B': ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'],
33-
'C': np.random.randn(8),
34-
'D': np.random.randn(8)})
35-
36-
37-
@pytest.fixture
38-
def mframe():
39-
index = MultiIndex(levels=[['foo', 'bar', 'baz', 'qux'],
40-
['one', 'two', 'three']],
41-
labels=[[0, 0, 0, 1, 1, 2, 2, 3, 3, 3],
42-
[0, 1, 2, 0, 1, 1, 2, 0, 1, 2]],
43-
names=['first', 'second'])
44-
return DataFrame(np.random.randn(10, 3),
45-
index=index,
46-
columns=['A', 'B', 'C'])
47-
48-
49-
@pytest.fixture
50-
def three_group():
51-
return DataFrame(
52-
{'A': ['foo', 'foo', 'foo', 'foo', 'bar', 'bar',
53-
'bar', 'bar', 'foo', 'foo', 'foo'],
54-
'B': ['one', 'one', 'one', 'two', 'one', 'one',
55-
'one', 'two', 'two', 'two', 'one'],
56-
'C': ['dull', 'dull', 'shiny', 'dull', 'dull', 'shiny',
57-
'shiny', 'dull', 'shiny', 'shiny', 'shiny'],
58-
'D': np.random.randn(11),
59-
'E': np.random.randn(11),
60-
'F': np.random.randn(11)})
61-
62-
6318
def test_agg_regression1(tsframe):
6419
grouped = tsframe.groupby([lambda x: x.year, lambda x: x.month])
6520
result = grouped.agg(np.mean)
@@ -87,6 +42,32 @@ def test_agg_ser_multi_key(df):
8742
tm.assert_series_equal(results, expected)
8843

8944

45+
def test_groupby_aggregation_mixed_dtype():
46+
47+
# GH 6212
48+
expected = DataFrame({
49+
'v1': [5, 5, 7, np.nan, 3, 3, 4, 1],
50+
'v2': [55, 55, 77, np.nan, 33, 33, 44, 11]},
51+
index=MultiIndex.from_tuples([(1, 95), (1, 99), (2, 95), (2, 99),
52+
('big', 'damp'),
53+
('blue', 'dry'),
54+
('red', 'red'), ('red', 'wet')],
55+
names=['by1', 'by2']))
56+
57+
df = DataFrame({
58+
'v1': [1, 3, 5, 7, 8, 3, 5, np.nan, 4, 5, 7, 9],
59+
'v2': [11, 33, 55, 77, 88, 33, 55, np.nan, 44, 55, 77, 99],
60+
'by1': ["red", "blue", 1, 2, np.nan, "big", 1, 2, "red", 1, np.nan,
61+
12],
62+
'by2': ["wet", "dry", 99, 95, np.nan, "damp", 95, 99, "red", 99,
63+
np.nan, np.nan]
64+
})
65+
66+
g = df.groupby(['by1', 'by2'])
67+
result = g[['v1', 'v2']].mean()
68+
tm.assert_frame_equal(result, expected)
69+
70+
9071
def test_agg_apply_corner(ts, tsframe):
9172
# nothing to group, all NA
9273
grouped = ts.groupby(ts * np.nan)

pandas/tests/groupby/common.py

-62
This file was deleted.

pandas/tests/groupby/conftest.py

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import pytest
2+
import numpy as np
3+
from pandas import MultiIndex, DataFrame
4+
from pandas.util import testing as tm
5+
6+
7+
@pytest.fixture
8+
def mframe():
9+
index = MultiIndex(levels=[['foo', 'bar', 'baz', 'qux'], ['one', 'two',
10+
'three']],
11+
labels=[[0, 0, 0, 1, 1, 2, 2, 3, 3, 3],
12+
[0, 1, 2, 0, 1, 1, 2, 0, 1, 2]],
13+
names=['first', 'second'])
14+
return DataFrame(np.random.randn(10, 3), index=index,
15+
columns=['A', 'B', 'C'])
16+
17+
18+
@pytest.fixture
19+
def df():
20+
return DataFrame(
21+
{'A': ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'],
22+
'B': ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'],
23+
'C': np.random.randn(8),
24+
'D': np.random.randn(8)})
25+
26+
27+
@pytest.fixture
28+
def ts():
29+
return tm.makeTimeSeries()
30+
31+
32+
@pytest.fixture
33+
def seriesd():
34+
return tm.getSeriesData()
35+
36+
37+
@pytest.fixture
38+
def tsd():
39+
return tm.getTimeSeriesData()
40+
41+
42+
@pytest.fixture
43+
def frame(seriesd):
44+
return DataFrame(seriesd)
45+
46+
47+
@pytest.fixture
48+
def tsframe(tsd):
49+
return DataFrame(tsd)
50+
51+
52+
@pytest.fixture
53+
def df_mixed_floats():
54+
return DataFrame({'A': ['foo', 'bar', 'foo', 'bar',
55+
'foo', 'bar', 'foo', 'foo'],
56+
'B': ['one', 'one', 'two', 'three',
57+
'two', 'two', 'one', 'three'],
58+
'C': np.random.randn(8),
59+
'D': np.array(
60+
np.random.randn(8), dtype='float32')})
61+
62+
63+
@pytest.fixture
64+
def three_group():
65+
return DataFrame({'A': ['foo', 'foo', 'foo',
66+
'foo', 'bar', 'bar',
67+
'bar', 'bar',
68+
'foo', 'foo', 'foo'],
69+
'B': ['one', 'one', 'one',
70+
'two', 'one', 'one', 'one', 'two',
71+
'two', 'two', 'one'],
72+
'C': ['dull', 'dull', 'shiny',
73+
'dull', 'dull', 'shiny', 'shiny',
74+
'dull', 'shiny', 'shiny', 'shiny'],
75+
'D': np.random.randn(11),
76+
'E': np.random.randn(11),
77+
'F': np.random.randn(11)})

0 commit comments

Comments
 (0)