|
| 1 | +import numpy as np |
| 2 | +import pytest |
| 3 | + |
| 4 | +from pandas import DataFrame, Index, MultiIndex |
| 5 | +from pandas.util import testing as tm |
| 6 | + |
| 7 | + |
| 8 | +@pytest.fixture |
| 9 | +def multiindex_dataframe_random_data(): |
| 10 | + """DataFrame with 2 level MultiIndex with random data""" |
| 11 | + index = MultiIndex(levels=[['foo', 'bar', 'baz', 'qux'], ['one', 'two', |
| 12 | + 'three']], |
| 13 | + labels=[[0, 0, 0, 1, 1, 2, 2, 3, 3, 3], |
| 14 | + [0, 1, 2, 0, 1, 1, 2, 0, 1, 2]], |
| 15 | + names=['first', 'second']) |
| 16 | + return DataFrame(np.random.randn(10, 3), index=index, |
| 17 | + columns=Index(['A', 'B', 'C'], name='exp')) |
| 18 | + |
| 19 | + |
| 20 | +@pytest.fixture |
| 21 | +def multiindex_year_month_day_dataframe_random_data(): |
| 22 | + """DataFrame with 3 level MultiIndex (year, month, day) covering |
| 23 | + first 100 business days from 2000-01-01 with random data""" |
| 24 | + tm.N = 100 |
| 25 | + tdf = tm.makeTimeDataFrame() |
| 26 | + ymd = tdf.groupby([lambda x: x.year, lambda x: x.month, |
| 27 | + lambda x: x.day]).sum() |
| 28 | + # use Int64Index, to make sure things work |
| 29 | + ymd.index.set_levels([lev.astype('i8') for lev in ymd.index.levels], |
| 30 | + inplace=True) |
| 31 | + ymd.index.set_names(['year', 'month', 'day'], inplace=True) |
| 32 | + return ymd |
0 commit comments