File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -1637,6 +1637,18 @@ def _has_valid_setitem_indexer(self, indexer) -> bool:
1637
1637
"Consider using .loc with a DataFrame indexer for automatic alignment." ,
1638
1638
)
1639
1639
1640
+ # Check for Series boolean indexer
1641
+ if com .is_bool_indexer (indexer ) and hasattr (indexer , "index" ) and isinstance (indexer .index , Index ):
1642
+ if indexer .index .inferred_type == "integer" :
1643
+ raise NotImplementedError (
1644
+ "iLocation based boolean "
1645
+ "indexing on an integer type "
1646
+ "is not available"
1647
+ )
1648
+ raise ValueError (
1649
+ "iLocation based boolean indexing cannot use an indexable as a mask"
1650
+ )
1651
+
1640
1652
if not isinstance (indexer , tuple ):
1641
1653
indexer = _tuplify (self .ndim , indexer )
1642
1654
Original file line number Diff line number Diff line change @@ -407,6 +407,19 @@ def test_getitem_frozenset_unique_in_column(self):
407
407
expected = Series ([1 ], name = frozenset (["KEY" ]))
408
408
tm .assert_series_equal (result , expected )
409
409
410
+ def test_series_boolean_indexer_iloc_consistency (self ):
411
+ # GH#60994 - Test consistency between __getitem__ and __setitem__ for Series boolean indexers
412
+ ser = Series ([0 , 1 , 2 ])
413
+ mask = Series ([True , False , False ])
414
+
415
+ # __getitem__ should raise NotImplementedError
416
+ with pytest .raises (NotImplementedError , match = "iLocation based boolean indexing on an integer type is not available" ):
417
+ ser .iloc [mask ]
418
+
419
+ # __setitem__ should also raise NotImplementedError for consistency
420
+ with pytest .raises (NotImplementedError , match = "iLocation based boolean indexing on an integer type is not available" ):
421
+ ser .iloc [mask ] = 10
422
+
410
423
411
424
class TestGetitemSlice :
412
425
def test_getitem_slice_float64 (self , frame_or_series ):
You can’t perform that action at this time.
0 commit comments