Skip to content
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

iloc with empty list raises IndexError #6536

Closed
dbew opened this issue Mar 4, 2014 · 2 comments · Fixed by #6551
Closed

iloc with empty list raises IndexError #6536

dbew opened this issue Mar 4, 2014 · 2 comments · Fixed by #6551
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves
Milestone

Comments

@dbew
Copy link
Contributor

dbew commented Mar 4, 2014

When you slice a dataframe with an empty list you get an IndexError instead of an empty dataframe. Slicing with a non-empty list works fine. Tested in pandas 0.13.1. This is a regression from pandas 0.11.0.

df = pd.DataFrame(np.arange(25.0).reshape((5,5)), columns=list('abcde'))

Slice with non-empty list.

[5 rows x 5 columns]
df.iloc[[1,2,3]]
Out[34]: 
    a   b   c   d   e
1   5   6   7   8   9
2  10  11  12  13  14
3  15  16  17  18  19

[3 rows x 5 columns]

Slice with empty list.

df.iloc[[]]
Traceback (most recent call last):
  File "/users/is/dbew/pyenvs/timeseries/lib/python2.7/site-packages/ipython-1.1.0_1_ahl1-py2.7.egg/IPython/core/interactiveshell.py", line 2830, in run_code
    exec code_obj in self.user_global_ns, self.user_ns
  File "<ipython-input-35-8806137779f8>", line 1, in <module>
    df.iloc[[]]
  File "/users/is/dbew/pyenvs/timeseries/lib/python2.7/site-packages/pandas-0.13.1-py2.7-linux-x86_64.egg/pandas/core/indexing.py", line 1028, in __getitem__
    return self._getitem_axis(key, axis=0)
  File "/users/is/dbew/pyenvs/timeseries/lib/python2.7/site-packages/pandas-0.13.1-py2.7-linux-x86_64.egg/pandas/core/indexing.py", line 1238, in _getitem_axis
    return self._get_loc(key, axis=axis)
  File "/users/is/dbew/pyenvs/timeseries/lib/python2.7/site-packages/pandas-0.13.1-py2.7-linux-x86_64.egg/pandas/core/indexing.py", line 73, in _get_loc
    return self.obj._ixs(key, axis=axis)
  File "/users/is/dbew/pyenvs/timeseries/lib/python2.7/site-packages/pandas-0.13.1-py2.7-linux-x86_64.egg/pandas/core/frame.py", line 1588, in _ixs
    result = self.reindex(i, takeable=True)
  File "/users/is/dbew/pyenvs/timeseries/lib/python2.7/site-packages/pandas-0.13.1-py2.7-linux-x86_64.egg/pandas/core/frame.py", line 2162, in reindex
    **kwargs)
  File "/users/is/dbew/pyenvs/timeseries/lib/python2.7/site-packages/pandas-0.13.1-py2.7-linux-x86_64.egg/pandas/core/generic.py", line 1565, in reindex
    takeable=takeable).__finalize__(self)
  File "/users/is/dbew/pyenvs/timeseries/lib/python2.7/site-packages/pandas-0.13.1-py2.7-linux-x86_64.egg/pandas/core/frame.py", line 2117, in _reindex_axes
    fill_value, limit, takeable=takeable)
  File "/users/is/dbew/pyenvs/timeseries/lib/python2.7/site-packages/pandas-0.13.1-py2.7-linux-x86_64.egg/pandas/core/frame.py", line 2126, in _reindex_index
    takeable=takeable)
  File "/users/is/dbew/pyenvs/timeseries/lib/python2.7/site-packages/pandas-0.13.1-py2.7-linux-x86_64.egg/pandas/core/index.py", line 1233, in reindex
    return self[target], target
  File "/users/is/dbew/pyenvs/timeseries/lib/python2.7/site-packages/pandas-0.13.1-py2.7-linux-x86_64.egg/pandas/core/index.py", line 624, in __getitem__
    result = arr_idx[key]
IndexError: arrays used as indices must be of integer (or boolean) type
@dbew
Copy link
Contributor Author

dbew commented Mar 4, 2014

Forgot to say, this works fine with .ix.

@dbew dbew closed this as completed Mar 4, 2014
@dbew dbew reopened this Mar 4, 2014
@jreback
Copy link
Contributor

jreback commented Mar 4, 2014

thanks...this is a bug

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants