Skip to content

Commit

Permalink
TST: split test_groupby.py (pandas-dev#20781)
Browse files Browse the repository at this point in the history
  • Loading branch information
jreback authored Apr 21, 2018
1 parent 0d199e4 commit 8def649
Show file tree
Hide file tree
Showing 13 changed files with 5,983 additions and 5,888 deletions.
71 changes: 26 additions & 45 deletions pandas/tests/groupby/aggregate/test_aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,51 +15,6 @@
import pandas.util.testing as tm


@pytest.fixture
def ts():
return tm.makeTimeSeries()


@pytest.fixture
def tsframe():
return DataFrame(tm.getTimeSeriesData())


@pytest.fixture
def df():
return DataFrame(
{'A': ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'],
'B': ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'],
'C': np.random.randn(8),
'D': np.random.randn(8)})


@pytest.fixture
def mframe():
index = MultiIndex(levels=[['foo', 'bar', 'baz', 'qux'],
['one', 'two', 'three']],
labels=[[0, 0, 0, 1, 1, 2, 2, 3, 3, 3],
[0, 1, 2, 0, 1, 1, 2, 0, 1, 2]],
names=['first', 'second'])
return DataFrame(np.random.randn(10, 3),
index=index,
columns=['A', 'B', 'C'])


@pytest.fixture
def three_group():
return DataFrame(
{'A': ['foo', 'foo', 'foo', 'foo', 'bar', 'bar',
'bar', 'bar', 'foo', 'foo', 'foo'],
'B': ['one', 'one', 'one', 'two', 'one', 'one',
'one', 'two', 'two', 'two', 'one'],
'C': ['dull', 'dull', 'shiny', 'dull', 'dull', 'shiny',
'shiny', 'dull', 'shiny', 'shiny', 'shiny'],
'D': np.random.randn(11),
'E': np.random.randn(11),
'F': np.random.randn(11)})


def test_agg_regression1(tsframe):
grouped = tsframe.groupby([lambda x: x.year, lambda x: x.month])
result = grouped.agg(np.mean)
Expand Down Expand Up @@ -87,6 +42,32 @@ def test_agg_ser_multi_key(df):
tm.assert_series_equal(results, expected)


def test_groupby_aggregation_mixed_dtype():

# GH 6212
expected = DataFrame({
'v1': [5, 5, 7, np.nan, 3, 3, 4, 1],
'v2': [55, 55, 77, np.nan, 33, 33, 44, 11]},
index=MultiIndex.from_tuples([(1, 95), (1, 99), (2, 95), (2, 99),
('big', 'damp'),
('blue', 'dry'),
('red', 'red'), ('red', 'wet')],
names=['by1', 'by2']))

df = DataFrame({
'v1': [1, 3, 5, 7, 8, 3, 5, np.nan, 4, 5, 7, 9],
'v2': [11, 33, 55, 77, 88, 33, 55, np.nan, 44, 55, 77, 99],
'by1': ["red", "blue", 1, 2, np.nan, "big", 1, 2, "red", 1, np.nan,
12],
'by2': ["wet", "dry", 99, 95, np.nan, "damp", 95, 99, "red", 99,
np.nan, np.nan]
})

g = df.groupby(['by1', 'by2'])
result = g[['v1', 'v2']].mean()
tm.assert_frame_equal(result, expected)


def test_agg_apply_corner(ts, tsframe):
# nothing to group, all NA
grouped = ts.groupby(ts * np.nan)
Expand Down
62 changes: 0 additions & 62 deletions pandas/tests/groupby/common.py

This file was deleted.

77 changes: 77 additions & 0 deletions pandas/tests/groupby/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import pytest
import numpy as np
from pandas import MultiIndex, DataFrame
from pandas.util import testing as tm


@pytest.fixture
def mframe():
index = MultiIndex(levels=[['foo', 'bar', 'baz', 'qux'], ['one', 'two',
'three']],
labels=[[0, 0, 0, 1, 1, 2, 2, 3, 3, 3],
[0, 1, 2, 0, 1, 1, 2, 0, 1, 2]],
names=['first', 'second'])
return DataFrame(np.random.randn(10, 3), index=index,
columns=['A', 'B', 'C'])


@pytest.fixture
def df():
return DataFrame(
{'A': ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'],
'B': ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'],
'C': np.random.randn(8),
'D': np.random.randn(8)})


@pytest.fixture
def ts():
return tm.makeTimeSeries()


@pytest.fixture
def seriesd():
return tm.getSeriesData()


@pytest.fixture
def tsd():
return tm.getTimeSeriesData()


@pytest.fixture
def frame(seriesd):
return DataFrame(seriesd)


@pytest.fixture
def tsframe(tsd):
return DataFrame(tsd)


@pytest.fixture
def df_mixed_floats():
return DataFrame({'A': ['foo', 'bar', 'foo', 'bar',
'foo', 'bar', 'foo', 'foo'],
'B': ['one', 'one', 'two', 'three',
'two', 'two', 'one', 'three'],
'C': np.random.randn(8),
'D': np.array(
np.random.randn(8), dtype='float32')})


@pytest.fixture
def three_group():
return DataFrame({'A': ['foo', 'foo', 'foo',
'foo', 'bar', 'bar',
'bar', 'bar',
'foo', 'foo', 'foo'],
'B': ['one', 'one', 'one',
'two', 'one', 'one', 'one', 'two',
'two', 'two', 'one'],
'C': ['dull', 'dull', 'shiny',
'dull', 'dull', 'shiny', 'shiny',
'dull', 'shiny', 'shiny', 'shiny'],
'D': np.random.randn(11),
'E': np.random.randn(11),
'F': np.random.randn(11)})
Loading

0 comments on commit 8def649

Please sign in to comment.