Skip to content

BUG: using .ix with a multi-index indexer #11400

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

Merged
merged 1 commit into from
Oct 27, 2015

Conversation

rekcahpassyla
Copy link
Contributor

closes #11372

Add an optional argument to _NDFrameIndexer to indicate
if the indexer is from a MultiIndex

@@ -11,6 +11,7 @@
from numpy import nan
from numpy.random import randn
import numpy as np
from numpy.testing import assert_allclose
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't use this

@jreback jreback added Bug Indexing Related to indexing on series/frames, not to indexes themselves MultiIndex labels Oct 21, 2015
@jreback jreback added this to the 0.17.1 milestone Oct 21, 2015
@jreback jreback changed the title BUG: Fixes GH11372 BUG: using .ix with a multi-index indexer Oct 21, 2015
@@ -788,6 +789,50 @@ def test_loc_setitem_multiindex(self):
result = df.loc[(t,n),'X']
self.assertEqual(result,3)

def test_ix_setitem_multiindex(self):
# GH5206
df = pd.DataFrame(np.random.random((5, 5)), columns='A,B,C,D,E'.split(','))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test for .ix and .loc (you can make a check function to simplify)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also going to change this test to not use np.random I think, as I note my row selection is <0.5 below, and thus the test inputs will be different between runs, which seems like a bad smell.

@rekcahpassyla
Copy link
Contributor Author

Updated with comments from review. I have consolidated the tests test_ix_setitem_multiindex and test_loc_setitem_multiindex into test_setitem_multiindex, running the union of the cases for both ix and loc.

@jreback
Copy link
Contributor

jreback commented Oct 25, 2015

pls add a whatsnew note (bug fixes), looks good otherwise.

@rekcahpassyla
Copy link
Contributor Author

Thanks - rebased on master, added whatsnew and pushed.

@@ -443,11 +443,14 @@ def can_do_equal_len():
# we have an equal len Frame
if isinstance(value, ABCDataFrame) and value.ndim > 1:
sub_indexer = list(indexer)
indexer_multiindex = isinstance(labels, MultiIndex)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about rename this to multiiindex_indexer (for a bit of consistency)

Add an optional argument to _NDFrameIndexer._align_series to indicate
if the indexer is from a MultiIndex
@rekcahpassyla
Copy link
Contributor Author

Renamed to multiindex_indexer and added docstring for _align_series

@jreback jreback merged commit 503359c into pandas-dev:master Oct 27, 2015
@jreback
Copy link
Contributor

jreback commented Oct 27, 2015

@rekcahpassyla thanks!

that was a nice deep dive. lots of other indexing issues if you'd like 😄

@rekcahpassyla
Copy link
Contributor Author

Welcome! In the short term, a bit pressed for time but we are testing our entire library against 0.17.0 and if anything else comes out of that, I'll be happy to have a crack at those too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves MultiIndex
Projects
None yet
2 participants