|
1 | 1 | # -*- coding: utf-8 -*-
|
2 | 2 |
|
3 |
| -from datetime import timedelta |
4 |
| -from itertools import product |
5 |
| -import nose |
6 | 3 | import re
|
7 | 4 | import warnings
|
8 | 5 |
|
9 |
| -from pandas import (DataFrame, date_range, period_range, MultiIndex, Index, |
10 |
| - CategoricalIndex, compat) |
11 |
| -from pandas.core.common import PerformanceWarning, UnsortedIndexError |
12 |
| -from pandas.indexes.base import InvalidIndexError |
13 |
| -from pandas.compat import range, lrange, u, PY3, long, lzip |
| 6 | +from datetime import timedelta |
| 7 | +from itertools import product |
| 8 | + |
| 9 | +import nose |
14 | 10 |
|
15 | 11 | import numpy as np
|
16 | 12 |
|
17 |
| -from pandas.util.testing import (assert_almost_equal, assertRaises, |
18 |
| - assertRaisesRegexp, assert_copy) |
| 13 | +import pandas as pd |
| 14 | + |
| 15 | +from pandas import (CategoricalIndex, DataFrame, Index, MultiIndex, Series, |
| 16 | + compat, date_range, period_range) |
| 17 | +from pandas.compat import PY3, long, lrange, lzip, range, u |
| 18 | +from pandas.core.common import PerformanceWarning, UnsortedIndexError |
| 19 | +from pandas.indexes.base import InvalidIndexError |
| 20 | +from pandas.lib import Timestamp |
19 | 21 |
|
20 | 22 | import pandas.util.testing as tm
|
21 | 23 |
|
22 |
| -import pandas as pd |
23 |
| -from pandas.lib import Timestamp |
| 24 | +from pandas.util.testing import (assertRaises, assertRaisesRegexp, |
| 25 | + assert_almost_equal, assert_copy) |
| 26 | + |
24 | 27 |
|
25 | 28 | from .common import Base
|
26 | 29 |
|
@@ -343,6 +346,19 @@ def test_set_levels_labels_names_bad_input(self):
|
343 | 346 | with tm.assertRaisesRegexp(TypeError, 'string'):
|
344 | 347 | self.index.set_names(names, level=0)
|
345 | 348 |
|
| 349 | + def test_series_index(self): |
| 350 | + # GH14730 |
| 351 | + index = MultiIndex.from_product([[1, 2, 3], ['A', 'B', 'C']]) |
| 352 | + x = Series(index=index, data=range(9)) |
| 353 | + y = Series([1, 3]) |
| 354 | + expected = Series( |
| 355 | + data=[0, 1, 2, 6, 7, 8], |
| 356 | + index=MultiIndex.from_product([[1, 3], ['A', 'B', 'C']])) |
| 357 | + actual_from_series = x.loc[y] |
| 358 | + actual_from_list = x.loc[[1, 3]] |
| 359 | + tm.assert_series_equal(expected, actual_from_list) |
| 360 | + tm.assert_series_equal(expected, actual_from_series) |
| 361 | + |
346 | 362 | def test_set_levels_categorical(self):
|
347 | 363 | # GH13854
|
348 | 364 | index = MultiIndex.from_arrays([list("xyzx"), [0, 1, 2, 3]])
|
|
0 commit comments