-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
BUG: Fix MultiIndex .loc with all numpy arrays #19772
Conversation
doc/source/whatsnew/v0.23.0.txt
Outdated
@@ -767,6 +767,7 @@ Indexing | |||
- Bug in :class:`IntervalIndex` where empty and purely NA data was constructed inconsistently depending on the construction method (:issue:`18421`) | |||
- Bug in :func:`IntervalIndex.symmetric_difference` where the symmetric difference with a non-``IntervalIndex`` did not raise (:issue:`18475`) | |||
- Bug in :class:`IntervalIndex` where set operations that returned an empty ``IntervalIndex`` had the wrong dtype (:issue:`19101`) | |||
- Bug in indexing where nested indexers having only numpy arrays are handled incorrectly (:issue:`19686`) |
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.
can you move to the mult-index section
@@ -711,3 +711,36 @@ def test_identity_slice_returns_new_object(self): | |||
|
|||
original_series[:3] = [7, 8, 9] | |||
assert all(sliced_series[:3] == [7, 8, 9]) | |||
|
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.
can you add Index here as well.
pandas/tests/indexing/test_loc.py
Outdated
(list, tuple, set, slice, np.ndarray, Series)) | ||
@pytest.mark.parametrize('indexer_type_2', | ||
(list, tuple, set, slice, np.ndarray, Series)) | ||
def test_loc_getitem_nested_indexer(self, indexer_type_1, indexer_type_2): |
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.
add the gh issue number & a 1-liner of what you are testing
pandas/tests/indexing/test_loc.py
Outdated
|
||
keys = ([10, 20], [2, 3]) | ||
types = (indexer_type_1, indexer_type_2) | ||
# check indexers with all the combinations of nested objects |
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.
blank line here
pandas/tests/indexing/test_loc.py
Outdated
df = pd.DataFrame(np.arange(len(index)), index=index, columns=['Data']) | ||
|
||
keys = ([10, 20], [2, 3]) | ||
types = (indexer_type_1, indexer_type_2) |
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 think you might be able to use np.ix_
for this, we also have some utilities in pandas/core/indexing.py
03c34be
to
07f31e4
Compare
Codecov Report
@@ Coverage Diff @@
## master #19772 +/- ##
=========================================
Coverage ? 91.6%
=========================================
Files ? 150
Lines ? 48887
Branches ? 0
=========================================
Hits ? 44785
Misses ? 4102
Partials ? 0
Continue to review full report at Codecov.
|
07f31e4
to
aa8302d
Compare
pandas/tests/indexing/test_loc.py
Outdated
a = [10, 20, 30] | ||
b = [1, 2, 3] | ||
index = pd.MultiIndex.from_product([a, b]) | ||
df = pd.DataFrame(np.arange(len(index)), index=index, columns=['Data']) |
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 need to add dtype='int64'
otherwise this won't match on windows (as np.arange defaults to int32)
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.
good catch, thanks
00c7ccd
to
f4e4b99
Compare
lgtm ping on green. |
@jreback all the checks have already finished |
thanks! |
git diff upstream/master -u -- "*.py" | flake8 --diff