Skip to content

add test for indexing with integer arrays #5127

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

Closed
wants to merge 2 commits into from

Conversation

hmeine
Copy link

@hmeine hmeine commented Oct 6, 2013

I had a try at solving issue #5006, but it does not look as trivial to me as @jreback suggested. ;-)

I added a test for indexing with int-typed arrays containing single indices, which currently fails. I spent some time reading test_indexing, because my hunch is that it could be better integrated with the existing tests (e.g. using check_result), but anyhow - any test is better than none, I guess.

The failing test goes through _iLocIndexer._getitem_axis() -> _NDFrameIndexer._get_loc() -> Series._ixs() -> index.get_value_at() -> util.get_value_at(), but I don't see the point where that should've been different right now.

Sorry, but I lack time for solving this at the moment.

hmeine added 2 commits October 6, 2013 20:56
(expected and actual types were swapped in output)
@cancan101
Copy link
Contributor

Don't forget to setup Travis.

@jtratner
Copy link
Contributor

jtratner commented Oct 6, 2013

Thanks for the test case! (doesn't matter to setup Travis if it's already a failing test). One thing that could be helpful is changing the test to show exactly what Series you expect, but that's minor.

Would be nice to have a known fail or something to keep track.

@jreback
Copy link
Contributor

jreback commented Oct 6, 2013

closing in favor of #5134

@jreback jreback closed this Oct 6, 2013
@jreback
Copy link
Contributor

jreback commented Oct 6, 2013

@hmeine

thanks for the test case. This is straightforward to fix; but a little bit non-intuitive when first looking at the code. There are many times when an exception is used to decide what happens, in this case a list causes the index engine to raise an InvalidIndexing error and then the series is ultimately reindexed (using the indicies as locations). The ndarray was actually returning the value directly (the theory goes that the list could actually be holding something else so best not to attempt a direct get using the cython code, while the ndarray can only hold indices so it is safe).

fixed up...thanks for the catch!

@hmeine
Copy link
Author

hmeine commented Oct 7, 2013

Ah, OK, I was not prepared for the exception trick. ;-)

I wonder however whether you plan to optimize the fix in the future – always copying (potentially large) arrays into lists seems to bring a potential performance regression, no? I would have added a TODO or an if len(key) > 1: – potentially in cython – or something.

@jreback
Copy link
Contributor

jreback commented Oct 7, 2013

always profile.

You would be optimizing us, and a single copy is generally not problematic. In addition, you would generally fall back to boolean indexing if you are selecting a sizable number of indices as that is generally how you would be generating them. Your usecase is quite specific (using nonzero) and is an edge case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants