@@ -726,16 +726,17 @@ def test_iloc_setitem_with_scalar_index(self, indexer, value):
726
726
727
727
@pytest .mark .filterwarnings ("ignore::UserWarning" )
728
728
def test_iloc_mask (self ):
729
- # GH 3631 , iloc with a mask (of a series) should raise
729
+ # GH 60994 , iloc with a mask (of a series) should return accordingly
730
730
df = DataFrame (list (range (5 )), index = list ("ABCDE" ), columns = ["a" ])
731
731
mask = df .a % 2 == 0
732
732
msg = "iLocation based boolean indexing cannot use an indexable as a mask"
733
733
with pytest .raises (ValueError , match = msg ):
734
734
df .iloc [mask ]
735
+
735
736
mask .index = range (len (mask ))
736
- msg = "iLocation based boolean indexing on an integer type is not available"
737
- with pytest . raises ( NotImplementedError , match = msg ):
738
- df . iloc [ mask ]
737
+ result = df . iloc [ mask ]
738
+ expected = df . iloc [[ 0 , 2 , 4 ]]
739
+ tm . assert_frame_equal ( result , expected )
739
740
740
741
# ndarray ok
741
742
result = df .iloc [np .array ([True ] * len (mask ), dtype = bool )]
@@ -753,18 +754,14 @@ def test_iloc_mask(self):
753
754
(None , ".iloc" ): "0b1100" ,
754
755
("index" , "" ): "0b11" ,
755
756
("index" , ".loc" ): "0b11" ,
756
- ("index" , ".iloc" ): (
757
- "iLocation based boolean indexing cannot use an indexable as a mask"
758
- ),
757
+ ("index" , ".iloc" ): "0b11" ,
759
758
("locs" , "" ): "Unalignable boolean Series provided as indexer "
760
759
"(index of the boolean Series and of the indexed "
761
760
"object do not match)." ,
762
761
("locs" , ".loc" ): "Unalignable boolean Series provided as indexer "
763
762
"(index of the boolean Series and of the "
764
763
"indexed object do not match)." ,
765
- ("locs" , ".iloc" ): (
766
- "iLocation based boolean indexing on an integer type is not available"
767
- ),
764
+ ("locs" , ".iloc" ): "0b1" ,
768
765
}
769
766
770
767
# UserWarnings from reindex of a boolean mask
@@ -780,7 +777,10 @@ def test_iloc_mask(self):
780
777
else :
781
778
accessor = df
782
779
answer = str (bin (accessor [mask ]["nums" ].sum ()))
783
- except (ValueError , IndexingError , NotImplementedError ) as err :
780
+ except (
781
+ ValueError ,
782
+ IndexingError ,
783
+ ) as err :
784
784
answer = str (err )
785
785
786
786
key = (
0 commit comments