|
| 1 | +from datetime import datetime |
1 | 2 | from warnings import catch_warnings
|
2 | 3 |
|
3 | 4 | import numpy as np
|
|
7 | 8 |
|
8 | 9 | import pandas as pd
|
9 | 10 | 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) |
11 | 13 | from pandas.tests.indexing.common import _mklbl
|
12 | 14 | from pandas.util import testing as tm
|
13 | 15 |
|
@@ -1340,3 +1342,20 @@ def test_panel_setitem_with_multiindex(self):
|
1340 | 1342 | p5.iloc[0, :, 0] = [1, 2]
|
1341 | 1343 | expected = Panel(arr, **axes)
|
1342 | 1344 | 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