Skip to content

IndexError when indexing into numpy array using a Series #8310

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
mirage007 opened this issue Sep 18, 2014 · 1 comment
Closed

IndexError when indexing into numpy array using a Series #8310

mirage007 opened this issue Sep 18, 2014 · 1 comment
Labels
API Design Duplicate Report Duplicate issue or pull request Indexing Related to indexing on series/frames, not to indexes themselves

Comments

@mirage007
Copy link

I'm getting a weird error in 0.14.1 that i didn't have in 0.10.1

>>> import numpy as np
>>> import pandas
>>> np.__version__
Out[8]: '1.8.2'
>>> pandas.__version__
Out[9]: '0.14.1'
>>> a = np.arange(10)
>>> b = pandas.Series([1,2,3])
>>> a[b]
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\IPython\core\interactiveshell.py", line 2746, in run_code
    exec code_obj in self.user_global_ns, self.user_ns
  File "<ipython-input-17-a686c4bc0a37>", line 1, in <module>
    a[b]
IndexError: unsupported iterator index

I would have expected to get something like array([1,2,3]), note this works if i use .values

>>> a[b.values]
Out[20]: array([1, 2, 3])

This would print out as expected in 0.10.1:

In [28]: numpy.__version__
Out[28]: '1.6.2'
In [29]: pandas.__version__
Out[29]: '0.10.1'
In [30]: a = numpy.arange(10)
In [31]: b = pandas.Series([1,2,3])
In [32]: a[b]
Out[32]: array([1, 2, 3])

Any ideas?

@jreback
Copy link
Contributor

jreback commented Sep 18, 2014

Series was refactored in 0.13.1, see here: http://pandas.pydata.org/pandas-docs/stable/whatsnew.html#whatsnew-0130-refactoring

This is a 'numpy' issue, I think 1.9 (or 1.10) addresses it. The work-around is as you suggest (or to wrap the numpy array as a Series).

see same issue in #6168 and #5776

thanks for the report

@jreback jreback closed this as completed Sep 18, 2014
@jreback jreback added API Design Indexing Related to indexing on series/frames, not to indexes themselves Duplicate Report Duplicate issue or pull request labels Sep 18, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Duplicate Report Duplicate issue or pull request Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

No branches or pull requests

2 participants