Skip to content

Commit 04daf4d

Browse files
eovesonPingviinituutti
authored andcommitted
TST: For GH4861, Period and datetime in multiindex (pandas-dev#23776)
1 parent a884734 commit 04daf4d

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

pandas/tests/indexing/test_multiindex.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from datetime import datetime
12
from warnings import catch_warnings
23

34
import numpy as np
@@ -7,7 +8,8 @@
78

89
import pandas as pd
910
from pandas import (
10-
DataFrame, Index, MultiIndex, Panel, Series, Timestamp, date_range)
11+
DataFrame, Index, MultiIndex, Panel, Period, Series, Timestamp, date_range,
12+
period_range)
1113
from pandas.tests.indexing.common import _mklbl
1214
from pandas.util import testing as tm
1315

@@ -1340,3 +1342,20 @@ def test_panel_setitem_with_multiindex(self):
13401342
p5.iloc[0, :, 0] = [1, 2]
13411343
expected = Panel(arr, **axes)
13421344
tm.assert_panel_equal(p5, expected)
1345+
1346+
1347+
def test_multiindex_period_datetime():
1348+
# GH4861, using datetime in period of multiindex raises exception
1349+
1350+
idx1 = Index(['a', 'a', 'a', 'b', 'b'])
1351+
idx2 = period_range('2012-01', periods=len(idx1), freq='M')
1352+
s = Series(np.random.randn(len(idx1)), [idx1, idx2])
1353+
1354+
# try Period as index
1355+
expected = s.iloc[0]
1356+
result = s.loc['a', Period('2012-01')]
1357+
assert result == expected
1358+
1359+
# try datetime as index
1360+
result = s.loc['a', datetime(2012, 1, 1)]
1361+
assert result == expected

0 commit comments

Comments
 (0)