Repository: mne-tools/mne-python

Issue:
Bug in peak_finder() and find_eog_events()
If no peaks were found there is _TypeError: can't multiply sequence by non-int of type 'float'_,
because in line 161 of peak_finder.py an empty list is multiplied by -1.0

A solution is to put in lines 156 and 157:
```
            peak_mags = np.array([])
            peak_inds = np.array([])
```
instead of
```
            peak_mags = []
            peak_inds = []
```

However, it will only delay a problem. Full solution has to contain also a verification of eog_events length in 68th line of eog.py, e.g.:
```
    if len(eog_events) > 0:
        eog_events[:, 0] = np.round(times[eog_events[:, 0] -
                                      raw.first_samp]).astype(int)
```
instead of just:
```
    eog_events[:, 0] = np.round(times[eog_events[:, 0] -
                                      raw.first_samp]).astype(int)
```
which assumes that eog_events is not empty.


Discussion:
please share a code snipped to replicate the pb. It will be used as
non-regression test.

thanks

I've had a similar problem before using bare `peak_finder` (`ValueError: zero-size array to reduction operation maximum which has no identity`), here is how to replicate:
```python
import numpy as np
from mne.preprocessing.peak_finder import peak_finder

values = np.arange(2, 1, 0.05)
peak_finder(values)
```
maybe just fixing `peak_finder` would be enough?
yes fix welcome

Hey there! Guess I would like to fix it if not already done
Go for it. Thx 

Resolving patch:
diff --git a/mne/preprocessing/peak_finder.py b/mne/preprocessing/peak_finder.py
--- a/mne/preprocessing/peak_finder.py
+++ b/mne/preprocessing/peak_finder.py
@@ -44,12 +44,11 @@ def peak_finder(x0, thresh=None, extrema=1, verbose=None):
     peak_finder(x)
     """
     x0 = np.asanyarray(x0)
-
-    if x0.ndim >= 2:
-        raise ValueError('The input data must be a 1D vector')
-
     s = x0.size
 
+    if x0.ndim >= 2 or s == 0:
+        raise ValueError('The input data must be a non empty 1D vector')
+
     if thresh is None:
         thresh = (np.max(x0) - np.min(x0)) / 4
 
@@ -161,6 +160,13 @@ def peak_finder(x0, thresh=None, extrema=1, verbose=None):
         peak_mags *= -1.0
         x0 = -x0
 
+    # ensure output type array
+    if not isinstance(peak_inds, np.ndarray):
+        peak_inds = np.atleast_1d(peak_inds).astype('int64')
+
+    if not isinstance(peak_mags, np.ndarray):
+        peak_mags = np.atleast_1d(peak_mags).astype('float64')
+
     # Plot if no output desired
     if len(peak_inds) == 0:
         logger.info('No significant peaks found')


Test patch:
diff --git a/mne/preprocessing/tests/test_peak_finder.py b/mne/preprocessing/tests/test_peak_finder.py
--- a/mne/preprocessing/tests/test_peak_finder.py
+++ b/mne/preprocessing/tests/test_peak_finder.py
@@ -1,10 +1,41 @@
-from numpy.testing import assert_array_equal
-
+from numpy.testing import assert_array_equal, assert_raises, assert_equal
+import numpy as np
+from mne.utils import run_tests_if_main
 from mne.preprocessing.peak_finder import peak_finder
 
 
 def test_peak_finder():
     """Test the peak detection method"""
-    x = [0, 2, 5, 0, 6, -1]
-    peak_inds, peak_mags = peak_finder(x)
+
+    # check for random data
+    rng = np.random.RandomState(42)
+    peak_inds, peak_mags = peak_finder(rng.randn(20))
+
+    assert_equal(peak_inds.dtype, np.dtype('int64'))
+    assert_equal(peak_mags.dtype, np.dtype('float64'))
+
+    # check for empty array as created in the #5025
+    with assert_raises(ValueError):
+        peak_finder(np.arange(2, 1, 0.05))
+
+    # check for empty array
+    with assert_raises(ValueError):
+        peak_finder([])
+
+    # check for monotonic function
+    peak_inds, peak_mags = peak_finder(np.arange(1, 2, 0.05))
+
+    assert_equal(peak_inds.dtype, np.dtype('int64'))
+    assert_equal(peak_mags.dtype, np.dtype('float64'))
+
+    # check for no peaks
+    peak_inds, peak_mags = peak_finder(np.zeros(20))
+
+    assert_equal(peak_inds.dtype, np.dtype('int64'))
+    assert_equal(peak_mags.dtype, np.dtype('float64'))
+
+    # check values
+    peak_inds, peak_mags = peak_finder([0, 2, 5, 0, 6, -1])
     assert_array_equal(peak_inds, [2, 4])
+
+run_tests_if_main()