From e7b453b7c2970fab0610cb2c16c5fe05d7ccb2e1 Mon Sep 17 00:00:00 2001 From: Hans Meine Date: Sun, 6 Oct 2013 20:51:41 +0200 Subject: [PATCH 1/2] fix message of assert_isinstance (expected and actual types were swapped in output) --- pandas/util/testing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/util/testing.py b/pandas/util/testing.py index 946a4d94b6045..9394c41627458 100644 --- a/pandas/util/testing.py +++ b/pandas/util/testing.py @@ -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. From ddb35476a7bebc55521b873b86cb879276d3be4f Mon Sep 17 00:00:00 2001 From: Hans Meine Date: Sun, 6 Oct 2013 20:52:23 +0200 Subject: [PATCH 2/2] add test for issue #5006 --- pandas/tests/test_indexing.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pandas/tests/test_indexing.py b/pandas/tests/test_indexing.py index 67c87277647c8..574d1a4ddb0c3 100644 --- a/pandas/tests/test_indexing.py +++ b/pandas/tests/test_indexing.py @@ -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 @@ -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