@@ -178,19 +178,20 @@ def setup_method(self, method):
178
178
self .unicode_index = tm .makeUnicodeIndex (10 , name = 'a' )
179
179
180
180
arr = np .random .randn (10 )
181
+ self .bool_series = Series (arr , index = self .bool_index , name = 'a' )
181
182
self .int_series = Series (arr , index = self .int_index , name = 'a' )
182
183
self .float_series = Series (arr , index = self .float_index , name = 'a' )
183
184
self .dt_series = Series (arr , index = self .dt_index , name = 'a' )
184
185
self .dt_tz_series = self .dt_tz_index .to_series (keep_tz = True )
185
186
self .period_series = Series (arr , index = self .period_index , name = 'a' )
186
187
self .string_series = Series (arr , index = self .string_index , name = 'a' )
188
+ self .unicode_series = Series (arr , index = self .unicode_index , name = 'a' )
187
189
188
190
types = ['bool' , 'int' , 'float' , 'dt' , 'dt_tz' , 'period' , 'string' ,
189
191
'unicode' ]
190
- fmts = ["{0}_{1}" .format (t , f )
191
- for t in types for f in ['index' , 'series' ]]
192
- self .objs = [getattr (self , f )
193
- for f in fmts if getattr (self , f , None ) is not None ]
192
+ self .indexes = [getattr (self , '{}_index' .format (t )) for t in types ]
193
+ self .series = [getattr (self , '{}_series' .format (t )) for t in types ]
194
+ self .objs = self .indexes + self .series
194
195
195
196
def check_ops_properties (self , props , filter = None , ignore_failures = False ):
196
197
for op in props :
@@ -997,6 +998,31 @@ def test_validate_bool_args(self):
997
998
with pytest .raises (ValueError ):
998
999
self .int_series .drop_duplicates (inplace = value )
999
1000
1001
+ def test_getitem (self ):
1002
+ for i in self .indexes :
1003
+ s = pd .Series (i )
1004
+
1005
+ assert i [0 ] == s .iloc [0 ]
1006
+ assert i [5 ] == s .iloc [5 ]
1007
+ assert i [- 1 ] == s .iloc [- 1 ]
1008
+
1009
+ assert i [- 1 ] == i [9 ]
1010
+
1011
+ pytest .raises (IndexError , i .__getitem__ , 20 )
1012
+ pytest .raises (IndexError , s .iloc .__getitem__ , 20 )
1013
+
1014
+ @pytest .mark .parametrize ('indexer_klass' , [list , pd .Index ])
1015
+ @pytest .mark .parametrize ('indexer' , [[True ] * 10 , [False ] * 10 ,
1016
+ [True , False , True , True , False ,
1017
+ False , True , True , False , True ]])
1018
+ def test_bool_indexing (self , indexer_klass , indexer ):
1019
+ # GH 22533
1020
+ for idx in self .indexes :
1021
+ exp_idx = [i for i in range (len (indexer )) if indexer [i ]]
1022
+ tm .assert_index_equal (idx [indexer_klass (indexer )], idx [exp_idx ])
1023
+ s = pd .Series (idx )
1024
+ tm .assert_series_equal (s [indexer_klass (indexer )], s .iloc [exp_idx ])
1025
+
1000
1026
1001
1027
class TestTranspose (Ops ):
1002
1028
errmsg = "the 'axes' parameter is not supported"
0 commit comments