Repository: mne-tools/mne-python

Issue:
MNE-Python failing test_io_set from mne.io.eeglab.tests.test_eeglab
Hello, I am also getting an error in the same test as issue  #4855 (but a different error, and in  version 0.16) : 

`    
    ================ FAILURES  ================
    _______________    test_io_set   _______________

    args = (), kwargs = {}
    def skipper_func(*args, **kwargs):
        """Skipper for normal test functions."""
        if skip_val():
            raise SkipTest(get_msg(f, msg))
        else:
>           return f(*args, **kwargs)

/user/ngayraud/home/anaconda2/lib/python2.7/site-packages/numpy/testing/decorators.py:147: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
mne/io/eeglab/tests/test_eeglab.py:234: in test_io_set
    np.array([0., 0., 0.]))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

x_id = array([ True,  True,  True], dtype=bool), y_id = array([False, False, False], dtype=bool), hasval = 'nan'

    def chk_same_position(x_id, y_id, hasval='nan'):
        """Handling nan/inf: check that x and y have the nan/inf at the same
            locations."""
        try:
            assert_array_equal(x_id, y_id)
        except AssertionError:
            msg = build_err_msg([x, y],
                                err_msg + '\nx and y %s location mismatch:'
                                % (hasval), verbose=verbose, header=header,
                                names=('x', 'y'), precision=precision)
>           raise AssertionError(msg)
E           AssertionError: 
E           Arrays are not equal
E           
E           x and y nan location mismatch:
E            x: array([ nan,  nan,  nan])
E            y: array([ 0.,  0.,  0.])

/user/ngayraud/home/anaconda2/lib/python2.7/site-packages/numpy/testing/utils.py:704: AssertionError`

I checked the solution proposed in MRG: Fix loc #4860, where all `[0., 0., 0.]` are replaced by `np.nan`.

It seems that the test passes when the line 231-232

`
assert_array_equal(raw.info['chs'][i]['loc'][:3],
                            np.array([0., 0., 0.]))
`

is replaced by

`assert_array_equal(raw.info['chs'][i]['loc'][:3], [np.nan] * 3)`



Discussion:
we recently changed empty EEG locations to NaN rather than 0.

what version are you testing?

version 0.16
indeed. I see the same error locally.

@larsoner any idea what this is not captured by travis?

I see it locally, too. It could be because we have a SkipTest to work around a NumPy 1.14.0 (which Travis uses) bug. PR welcome to change the test.

Resolving patch:
diff --git a/mne/inverse_sparse/mxne_optim.py b/mne/inverse_sparse/mxne_optim.py
--- a/mne/inverse_sparse/mxne_optim.py
+++ b/mne/inverse_sparse/mxne_optim.py
@@ -71,11 +71,11 @@ def prox_l21(Y, alpha, n_orient, shape=None, is_stft=False):
     -------
     >>> Y = np.tile(np.array([0, 4, 3, 0, 0], dtype=np.float), (2, 1))
     >>> Y = np.r_[Y, np.zeros_like(Y)]
-    >>> print(Y)
-    [[0. 4. 3. 0. 0.]
-     [0. 4. 3. 0. 0.]
-     [0. 0. 0. 0. 0.]
-     [0. 0. 0. 0. 0.]]
+    >>> print(Y)  # doctest:+SKIP
+    [[ 0.  4.  3.  0.  0.]
+     [ 0.  4.  3.  0.  0.]
+     [ 0.  0.  0.  0.  0.]
+     [ 0.  0.  0.  0.  0.]]
     >>> Yp, active_set = prox_l21(Y, 2, 2)
     >>> print(Yp)  # doctest:+SKIP
     [[0.         2.86862915 2.15147186 0.         0.        ]
@@ -145,11 +145,11 @@ def prox_l1(Y, alpha, n_orient):
     -------
     >>> Y = np.tile(np.array([1, 2, 3, 2, 0], dtype=np.float), (2, 1))
     >>> Y = np.r_[Y, np.zeros_like(Y)]
-    >>> print(Y)
-    [[1. 2. 3. 2. 0.]
-     [1. 2. 3. 2. 0.]
-     [0. 0. 0. 0. 0.]
-     [0. 0. 0. 0. 0.]]
+    >>> print(Y)  # doctest:+SKIP
+    [[ 1.  2.  3.  2.  0.]
+     [ 1.  2.  3.  2.  0.]
+     [ 0.  0.  0.  0.  0.]
+     [ 0.  0.  0.  0.  0.]]
     >>> Yp, active_set = prox_l1(Y, 2, 2)
     >>> print(Yp)  # doctest:+SKIP
     [[0.         0.58578644 1.58578644 0.58578644 0.        ]


Test patch:
diff --git a/mne/io/eeglab/tests/test_eeglab.py b/mne/io/eeglab/tests/test_eeglab.py
--- a/mne/io/eeglab/tests/test_eeglab.py
+++ b/mne/io/eeglab/tests/test_eeglab.py
@@ -229,7 +229,7 @@ def test_io_set():
     for i in range(3):
         assert_equal(raw.info['chs'][i]['ch_name'], ch_names[i])
         assert_array_equal(raw.info['chs'][i]['loc'][:3],
-                           np.array([0., 0., 0.]))
+                           np.array([np.nan, np.nan, np.nan]))
 
 
 @testing.requires_testing_data