Skip to content
19 changes: 19 additions & 0 deletions pandas/tests/indexes/period/test_period.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from datetime import datetime

import numpy as np
import pytest

Expand Down Expand Up @@ -570,3 +572,20 @@ def test_maybe_convert_timedelta():
offset = offsets.BusinessDay()
with pytest.raises(ValueError, match='freq'):
pi._maybe_convert_timedelta(offset)


def test_multiindex_period_datetime():
# GH4861, using datetime in period of multiindex raises exception

idx1 = Index(['a', 'a', 'a', 'b', 'b'])
idx2 = period_range('2012-01', periods=len(idx1), freq='M')
s = Series(np.random.randn(len(idx1)), [idx1, idx2])

# try Period as index
expected = s.iloc[0]
result = s.loc['a', Period('2012-01')]
assert result == expected

# try datetime as index
result = s.loc['a', datetime(2012, 1, 1)]
assert result == expected