def safe_indexing(X, indices):
 if hasattr(X, 'iloc'):
  try:
   return X.iloc[indices]
  except ValueError:
   warnings.warn('Copying input dataframe for slicing.', DataConversionWarning)
   return X.copy().iloc[indices]
 elif hasattr(X, 'shape'):
  if (hasattr(X, 'take') and (hasattr(indices, 'dtype') and (indices.dtype.kind == 'i'))):
   return X.take(indices, axis=0)
  else:
   return X[indices]
 else:
  return [X[idx] for idx in indices]

def safe_indexing ( X , indices ) : if hasattr ( X , 'iloc' ) : try : return X . iloc [ indices ] except ValueError : warnings . warn ( 'Copying input dataframe for slicing.' , DataConversionWarning ) return X . copy ( ) . iloc [ indices ] elif hasattr ( X , 'shape' ) : if ( hasattr ( X , 'take' ) and ( hasattr ( indices , 'dtype' ) and ( indices . dtype . kind == 'i' ) ) ) : return X . take ( indices , axis = 0 ) else : return X [ indices ] else : return [ X [ idx ] for idx in indices ]
return items or rows from x using indices .