Skip to content

Commit 6a1ddb1

Browse files
simonjayhawkinsPingviinituutti
authored andcommitted
TST: split up pandas/tests/indexing/test_multiindex.py (pandas-dev#23912)
1 parent ce8ac04 commit 6a1ddb1

16 files changed

+2363
-2249
lines changed

pandas/tests/indexing/multiindex/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from datetime import datetime
2+
3+
import numpy as np
4+
5+
from pandas import Index, Period, Series, period_range
6+
7+
8+
def test_multiindex_period_datetime():
9+
# GH4861, using datetime in period of multiindex raises exception
10+
11+
idx1 = Index(['a', 'a', 'a', 'b', 'b'])
12+
idx2 = period_range('2012-01', periods=len(idx1), freq='M')
13+
s = Series(np.random.randn(len(idx1)), [idx1, idx2])
14+
15+
# try Period as index
16+
expected = s.iloc[0]
17+
result = s.loc['a', Period('2012-01')]
18+
assert result == expected
19+
20+
# try datetime as index
21+
result = s.loc['a', datetime(2012, 1, 1)]
22+
assert result == expected

0 commit comments

Comments
 (0)