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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion pandas/tests/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
from pandas.core.api import (DataFrame, Index, Series, Panel, notnull, isnull,
MultiIndex, DatetimeIndex, Float64Index, Timestamp)
from pandas.util.testing import (assert_almost_equal, assert_series_equal,
assert_frame_equal, assert_panel_equal)
assert_frame_equal, assert_panel_equal,
assert_isinstance)
from pandas import compat, concat

import pandas.util.testing as tm
Expand Down Expand Up @@ -1841,6 +1842,16 @@ def check_slicing_positional(index):
#self.assertRaises(TypeError, lambda : s.iloc[2.0:5.0])
#self.assertRaises(TypeError, lambda : s.iloc[2:5.0])

def test_array_indexing(self):
"""test that array indexing returns a sequence by calling len()"""
column = Series(np.arange(10))
indices = np.arange(5, 10)
assert_isinstance(column.iloc[indices], Series)
indices = np.array([5], dtype = int)
assert_isinstance(column.iloc[indices], Series)
indices = np.array([], dtype = int)
assert_isinstance(column.iloc[indices], Series)


if __name__ == '__main__':
import nose
Expand Down
2 changes: 1 addition & 1 deletion pandas/util/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def assert_isinstance(obj, class_type_or_tuple):
"""asserts that obj is an instance of class_type_or_tuple"""
assert isinstance(obj, class_type_or_tuple), (
"Expected object to be of type %r, found %r instead" % (
type(obj), class_type_or_tuple))
class_type_or_tuple, type(obj)))

def assert_equal(a, b, msg=""):
"""asserts that a equals b, like nose's assert_equal, but allows custom message to start.
Expand Down