LSR/env/lib/python3.6/site-packages/pandas/tests/groupby/conftest.py

125 lines
2.9 KiB
Python
Raw Normal View History

2020-06-04 17:24:47 +02:00
import numpy as np
import pytest
from pandas import DataFrame, MultiIndex
import pandas._testing as tm
from pandas.core.groupby.base import reduction_kernels, transformation_kernels
@pytest.fixture
def mframe():
index = MultiIndex(
levels=[["foo", "bar", "baz", "qux"], ["one", "two", "three"]],
codes=[[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 tsd():
return tm.getTimeSeriesData()
@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),
}
)
@pytest.fixture(params=sorted(reduction_kernels))
def reduction_func(request):
"""yields the string names of all groupby reduction functions, one at a time.
"""
return request.param
@pytest.fixture(params=transformation_kernels)
def transformation_func(request):
"""yields the string names of all groupby transformation functions."""
return request.param
@pytest.fixture(params=sorted(reduction_kernels) + sorted(transformation_kernels))
def groupby_func(request):
"""yields both aggregation and transformation functions."""
return request.param