Repository: scipy/scipy

Issue:
Passing array as window into signal.resample() fails
The docs say I can pass an `array` into the `window` keyword argument of `scipy.signal.resample`, however the following code fails

```
osfactor = 128
sig = numpy.arange(128)

win = scipy.signal.get_window(('kaiser', 8.0), osfactor // 2)
sig = scipy.signal.resample(sig, len(sig) * osfactor, window=win)
```

with the following message:

```
Traceback (most recent call last):
  File "test.py", line 8, in <module>
    sig = scipy.signal.resample(sig, len(sig) * osfactor, window=win)
  File "/usr/local/Cellar/python/2.7.6_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/scipy/signal/signaltools.py", line 1325, in resample
    W = ifftshift(get_window(window, Nx))
  File "/usr/local/Cellar/python/2.7.6_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/scipy/signal/windows.py", line 1389, in get_window
    if winstr in ['blackman', 'black', 'blk']:
UnboundLocalError: local variable 'winstr' referenced before assignment
```

Using

```
numpy.__version__ = 1.8.1
scipy.__version__ = 0.13.3
```



Discussion:
When you use an array as the window, it must be the same length as the signal.  From the _Notes_ section of the `resample` docstring:

```
If `window` is an array of the same length as `x.shape[axis]` it is
assumed to be the window to be applied directly in the Fourier
domain (with dc and low-frequency first).
```

---

Your example _does_ demonstrate a bug in scipy.  That bug is relatively minor and not the cause of the problem you have, but it is the cause of the somewhat cryptic error message.    The bug is in `scipy.signal.get_window`.   When the argument to `get_window` is an array, the code ends up referring to an undefined variable `winstr`.


Resolving patch:
diff --git a/scipy/signal/windows.py b/scipy/signal/windows.py
--- a/scipy/signal/windows.py
+++ b/scipy/signal/windows.py
@@ -1342,7 +1342,7 @@ def cosine(M, sym=True):
     w : ndarray
         The window, with the maximum value normalized to 1 (though the value 1
         does not appear if `M` is even and `sym` is True).
-    
+
     Notes
     -----
 
@@ -1464,6 +1464,8 @@ def get_window(window, Nx, fftbins=True):
                                     "more parameters  -- pass a tuple.")
             else:
                 winstr = window
+        else:
+            raise ValueError("%s as window type is not supported." % str(type(window)))
 
         if winstr in ['blackman', 'black', 'blk']:
             winfunc = blackman


Test patch:
diff --git a/scipy/signal/tests/test_windows.py b/scipy/signal/tests/test_windows.py
--- a/scipy/signal/tests/test_windows.py
+++ b/scipy/signal/tests/test_windows.py
@@ -1,11 +1,10 @@
 from __future__ import division, print_function, absolute_import
 
-
 import warnings
 import numpy as np
 from numpy import array
 from numpy.testing import (assert_array_almost_equal, assert_array_equal,
-                           run_module_suite)
+                           run_module_suite, assert_raises)
 from scipy import signal
 
 
@@ -118,6 +117,14 @@ def test_cheb_even(self):
             w = signal.get_window(('chebwin', -40), 54, fftbins=False)
         assert_array_almost_equal(w, cheb_even_true, decimal=4)
 
+    def test_array_as_window(self):
+        # github issue 3603
+        osfactor = 128
+        sig = np.arange(128)
+
+        win = signal.get_window(('kaiser', 8.0), osfactor // 2)
+        assert_raises(ValueError, signal.resample, (sig, len(sig) * osfactor), {'window': win})
+
 
 def test_windowfunc_basics():
     for window_name, params in window_funcs: