title: scikit-learn Imputer class - possible bug with median strategy?
body: <p>I'm trying to use sklearn.preprocessing.Imputer to impute missing values using their median.
  I've noticed that the first column in my data gets deleted, and for no good reason (the missing values are pretty sparse).
  To clarify:</p>
  
  <pre><code>&gt;&gt;&gt; X = np.array([[1,2,3],[4,5,np.nan], [7,8,9]])
  &gt;&gt;&gt; X
  array([[  1.,   2.,   3.],
         [  4.,   5.,  nan],
         [  7.,   8.,   9.]])
  &gt;&gt;&gt; Imputer(strategy='median').fit_transform(X)
  C:\Python27\lib\site-packages\sklearn\preprocessing\imputation.py:307: DeprecationWarning: using a boolean instead of an integer will result in an error in the future
    median[np.ma.getmask(median_masked)] = np.nan
  array([[ 2.,  3.],
         [ 5.,  6.],
         [ 8.,  9.]])
  </code></pre>
  
  <p>I'm using python2.7, sklearn version 0.14.1 with numpy 1.8.0.
  I've tracked this to line 307 of the _dense_fit method of Imputation.py:</p>
  
  <pre><code>[304] median_masked = np.ma.median(masked_X, axis=axis)
  [305] # Avoid the warning "Warning: converting a masked element to nan."
  [306] median = np.ma.getdata(median_masked)
  [307] median[np.ma.getmask(median_masked)] = np.nan
  </code></pre>
  
  <p>the <code>median_masked</code> variable in my case contains no np.nan-s - only float values. However it appears that <code>np.ma.getmask(median_masked)</code> returns <code>False</code> instead of the mask itself, which results in the first column median being converted to np.nan, and in downstream computation - it get's deleted. 
  According to numpy <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.ma.getmask.html#numpy.ma.getmask" rel="nofollow">docs</a>, this is actually an expected behavior, and np.ma.getmaskarray should be used instead.</p>
  
  <p>I was wondering if my analysis is valid, and was hoping for advice on how to receive the correct behavior.</p>
  
  <p>Thanks</p>