Skip to content

Commit

Permalink
TST: For GH4861, Period and datetime in multiindex (pandas-dev#23776)
Browse files Browse the repository at this point in the history
  • Loading branch information
eoveson authored and Pingviinituutti committed Feb 28, 2019
1 parent a884734 commit 04daf4d
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion pandas/tests/indexing/test_multiindex.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import datetime
from warnings import catch_warnings

import numpy as np
Expand All @@ -7,7 +8,8 @@

import pandas as pd
from pandas import (
DataFrame, Index, MultiIndex, Panel, Series, Timestamp, date_range)
DataFrame, Index, MultiIndex, Panel, Period, Series, Timestamp, date_range,
period_range)
from pandas.tests.indexing.common import _mklbl
from pandas.util import testing as tm

Expand Down Expand Up @@ -1340,3 +1342,20 @@ def test_panel_setitem_with_multiindex(self):
p5.iloc[0, :, 0] = [1, 2]
expected = Panel(arr, **axes)
tm.assert_panel_equal(p5, expected)


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

0 comments on commit 04daf4d

Please sign in to comment.