#NEWLINE# def safe_mask( X , mask ) : #NEWLINE# #INDENT# 'Return a mask which is safe to use on X.\n\n    Parameters\n    ----------\n    X : {array-like, sparse matrix}\n        Data on which to apply mask.\n\n    mask: array\n        Mask to be used on X.\n\n    Returns\n    -------\n        mask\n    ' #NEWLINE# mask = np . asarray ( mask ) #NEWLINE# if np . issubdtype ( mask . dtype , np . int ) : #NEWLINE# #INDENT# return mask #NEWLINE# #UNINDENT# if hasattr ( X , 'toarray' ) : #NEWLINE# #INDENT# ind = np . arange ( mask . shape [ 0 ] ) #NEWLINE# mask = ind [ ind ] #NEWLINE# #UNINDENT# return mask