@@ -275,7 +275,7 @@ def _index_with(indexer):
275
275
# special handling of boolean data with NAs stored in object
276
276
# arrays. Since we can't represent NA with dtype=bool
277
277
if _is_bool_indexer (key ):
278
- self ._check_bool_indexer (key )
278
+ key = self ._check_bool_indexer (key )
279
279
key = np .asarray (key , dtype = bool )
280
280
return _index_with (key )
281
281
@@ -392,17 +392,12 @@ def __setitem__(self, key, value):
392
392
# Could not hash item
393
393
pass
394
394
395
- self ._check_bool_indexer (key )
395
+ key = self ._check_bool_indexer (key )
396
396
397
397
# special handling of boolean data with NAs stored in object
398
398
# arrays. Sort of an elaborate hack since we can't represent boolean
399
399
# NA. Hmm
400
400
if isinstance (key , np .ndarray ) and key .dtype == np .object_ :
401
- mask = isnull (key )
402
- if mask .any ():
403
- raise ValueError ('cannot index with vector containing '
404
- 'NA / NaN values' )
405
-
406
401
if set ([True , False ]).issubset (set (key )):
407
402
key = np .asarray (key , dtype = bool )
408
403
values [key ] = value
@@ -413,10 +408,18 @@ def __setitem__(self, key, value):
413
408
def _check_bool_indexer (self , key ):
414
409
# boolean indexing, need to check that the data are aligned, otherwise
415
410
# disallowed
411
+ result = key
416
412
if isinstance (key , Series ) and key .dtype == np .bool_ :
417
413
if not key .index .equals (self .index ):
418
- raise Exception ('can only boolean index with like-indexed '
419
- 'Series or raw ndarrays' )
414
+ result = key .reindex (self .index )
415
+
416
+ if isinstance (result , np .ndarray ) and result .dtype == np .object_ :
417
+ mask = isnull (result )
418
+ if mask .any ():
419
+ raise ValueError ('cannot index with vector containing '
420
+ 'NA / NaN values' )
421
+
422
+ return result
420
423
421
424
def __setslice__ (self , i , j , value ):
422
425
"""Set slice equal to given value(s)"""
0 commit comments