-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Indexing MultiIndex with Series failed. #15041
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,29 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from datetime import timedelta | ||
from itertools import product | ||
import nose | ||
import re | ||
import warnings | ||
|
||
from pandas import (DataFrame, date_range, period_range, MultiIndex, Index, | ||
CategoricalIndex, compat) | ||
from pandas.core.common import PerformanceWarning, UnsortedIndexError | ||
from pandas.indexes.base import InvalidIndexError | ||
from pandas.compat import range, lrange, u, PY3, long, lzip | ||
from datetime import timedelta | ||
from itertools import product | ||
|
||
import nose | ||
|
||
import numpy as np | ||
|
||
from pandas.util.testing import (assert_almost_equal, assertRaises, | ||
assertRaisesRegexp, assert_copy) | ||
import pandas as pd | ||
|
||
from pandas import (CategoricalIndex, DataFrame, Index, MultiIndex, Series, | ||
compat, date_range, period_range) | ||
from pandas.compat import PY3, long, lrange, lzip, range, u | ||
from pandas.core.common import PerformanceWarning, UnsortedIndexError | ||
from pandas.indexes.base import InvalidIndexError | ||
from pandas.lib import Timestamp | ||
|
||
import pandas.util.testing as tm | ||
|
||
import pandas as pd | ||
from pandas.lib import Timestamp | ||
from pandas.util.testing import (assertRaises, assertRaisesRegexp, | ||
assert_almost_equal, assert_copy) | ||
|
||
|
||
from .common import Base | ||
|
||
|
@@ -343,6 +346,19 @@ def test_set_levels_labels_names_bad_input(self): | |
with tm.assertRaisesRegexp(TypeError, 'string'): | ||
self.index.set_names(names, level=0) | ||
|
||
def test_series_index(self): | ||
# GH14730 | ||
index = MultiIndex.from_product([[1, 2, 3], ['A', 'B', 'C']]) | ||
x = Series(index=index, data=range(9)) | ||
y = Series([1, 3]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. put this is tests/test_multilevel or test_indexing find a very similar test (iow indexing a mi with list/ndarray) and put after |
||
expected = Series( | ||
data=[0, 1, 2, 6, 7, 8], | ||
index=MultiIndex.from_product([[1, 3], ['A', 'B', 'C']])) | ||
actual_from_series = x.loc[y] | ||
actual_from_list = x.loc[[1, 3]] | ||
tm.assert_series_equal(expected, actual_from_list) | ||
tm.assert_series_equal(expected, actual_from_series) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. result = ... |
||
|
||
def test_set_levels_categorical(self): | ||
# GH13854 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. check empty series as well |
||
index = MultiIndex.from_arrays([list("xyzx"), [0, 1, 2, 3]]) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can prob just
list(key)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought taking the
.values
was more explicit, butlist
is probably more familiar. Changed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no
.values
is fraught with issues as it converts dtypes, we don't use it internally if at all possible.