Repository: dask/dask

Issue:
python 2.7 numpy 1.16.rc and dask fail to import
It seems that dask is failing to import on python 2.7 and numpy 1.16.rc

<details> <summary> ci build for scikit-image showing failure </summary>
https://travis-ci.org/scikit-image/scikit-image/jobs/474126834#L3629

```
$ pip list
Package                       Version     Location                                    
----------------------------- ----------- --------------------------------------------
atomicwrites                  1.2.1       
attrs                         18.2.0      
backports.functools-lru-cache 1.5         
certifi                       2018.11.29  
chardet                       3.0.4       
cloudpickle                   0.6.1       
codecov                       2.0.15      
configparser                  3.5.0       
coverage                      5.0a4       
cycler                        0.10.0      
Cython                        0.28.1      
dask                          1.0.0       
decorator                     4.3.0       
enum34                        1.1.6       
flake8                        3.6.0       
funcsigs                      1.0.2       
idna                          2.8         
kiwisolver                    1.0.1       
matplotlib                    2.2.3       
mccabe                        0.6.1       
more-itertools                5.0.0       
networkx                      2.2         
numpy                         1.16.0rc1   
pathlib2                      2.3.3       
Pillow                        5.3.0       
pip                           18.1        
pluggy                        0.8.0       
py                            1.7.0       
pyamg                         4.0.0       
pybind11                      2.2.4       
pycodestyle                   2.4.0       
pyflakes                      2.0.0       
pyparsing                     2.3.0       
pytest                        4.0.2       
pytest-cov                    2.6.0       
python-dateutil               2.7.5       
pytz                          2018.7      
PyWavelets                    1.0.1       
requests                      2.21.0      
requirements-parser           0.2.0       
scandir                       1.9.0       
scikit-image                  0.14.2.dev0 /home/travis/build/scikit-image/scikit-image
scipy                         1.2.0       
setuptools                    40.6.3      
six                           1.12.0      
subprocess32                  3.5.3       
toolz                         0.9.0       
urllib3                       1.24.1      
wheel                         0.32.3      
```

```python
==================================== ERRORS ====================================
_________________________ ERROR collecting __init__.py _________________________
skimage/__init__.py:167: in <module>
    from .util.dtype import (img_as_float32,
skimage/util/__init__.py:6: in <module>
    from .apply_parallel import apply_parallel
skimage/util/apply_parallel.py:8: in <module>
    import dask.array as da
../../../venv/lib/python2.7/site-packages/dask/array/__init__.py:9: in <module>
    from .routines import (take, choose, argwhere, where, coarsen, insert,
../../../venv/lib/python2.7/site-packages/dask/array/routines.py:256: in <module>
    @wraps(np.matmul)
/opt/python/2.7.14/lib/python2.7/functools.py:33: in update_wrapper
    setattr(wrapper, attr, getattr(wrapped, attr))
E   AttributeError: 'numpy.ufunc' object has no attribute '__module__'
```

xref: https://github.com/scikit-image/scikit-image/pull/3632

</details>

```
conda create --name py27 py=2 dask=1 --yes
conda activate py27
conda remove numpy --force --offline --yes
pip uninstall numpy
pip install numpy --pre
python -c 'from dask import array as da'
```

```
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/mark2/miniconda3/envs/py27/lib/python2.7/site-packages/dask/array/__init__.py", line 9, in <module>
    from .routines import (take, choose, argwhere, where, coarsen, insert,
  File "/home/mark2/miniconda3/envs/py27/lib/python2.7/site-packages/dask/array/routines.py", line 256, in <module>
    @wraps(np.matmul)
  File "/home/mark2/miniconda3/envs/py27/lib/python2.7/functools.py", line 33, in update_wrapper
    setattr(wrapper, attr, getattr(wrapped, attr))
AttributeError: 'numpy.ufunc' object has no attribute '__module__'
```


Discussion:
It looks like there is a dask.array.utils.safe_wraps that is already
imported in routines.py that might resolve this?

On Tue, Jan 1, 2019 at 9:19 AM Mark Harfouche <notifications@github.com>
wrote:

> It seems that dask is failing to import on python 2.7 and numpy 1.16.rc
> ci build for scikit-image showing failure
> https://travis-ci.org/scikit-image/scikit-image/jobs/474126834#L3629
>
> $ pip list
> Package                       Version     Location
> ----------------------------- ----------- --------------------------------------------
> atomicwrites                  1.2.1
> attrs                         18.2.0
> backports.functools-lru-cache 1.5
> certifi                       2018.11.29
> chardet                       3.0.4
> cloudpickle                   0.6.1
> codecov                       2.0.15
> configparser                  3.5.0
> coverage                      5.0a4
> cycler                        0.10.0
> Cython                        0.28.1
> dask                          1.0.0
> decorator                     4.3.0
> enum34                        1.1.6
> flake8                        3.6.0
> funcsigs                      1.0.2
> idna                          2.8
> kiwisolver                    1.0.1
> matplotlib                    2.2.3
> mccabe                        0.6.1
> more-itertools                5.0.0
> networkx                      2.2
> numpy                         1.16.0rc1
> pathlib2                      2.3.3
> Pillow                        5.3.0
> pip                           18.1
> pluggy                        0.8.0
> py                            1.7.0
> pyamg                         4.0.0
> pybind11                      2.2.4
> pycodestyle                   2.4.0
> pyflakes                      2.0.0
> pyparsing                     2.3.0
> pytest                        4.0.2
> pytest-cov                    2.6.0
> python-dateutil               2.7.5
> pytz                          2018.7
> PyWavelets                    1.0.1
> requests                      2.21.0
> requirements-parser           0.2.0
> scandir                       1.9.0
> scikit-image                  0.14.2.dev0 /home/travis/build/scikit-image/scikit-image
> scipy                         1.2.0
> setuptools                    40.6.3
> six                           1.12.0
> subprocess32                  3.5.3
> toolz                         0.9.0
> urllib3                       1.24.1
> wheel                         0.32.3
>
> ==================================== ERRORS ====================================
> _________________________ ERROR collecting __init__.py _________________________
> skimage/__init__.py:167: in <module>
>     from .util.dtype import (img_as_float32,
> skimage/util/__init__.py:6: in <module>
>     from .apply_parallel import apply_parallel
> skimage/util/apply_parallel.py:8: in <module>
>     import dask.array as da
> ../../../venv/lib/python2.7/site-packages/dask/array/__init__.py:9: in <module>
>     from .routines import (take, choose, argwhere, where, coarsen, insert,
> ../../../venv/lib/python2.7/site-packages/dask/array/routines.py:256: in <module>
>     @wraps(np.matmul)/opt/python/2.7.14/lib/python2.7/functools.py:33: in update_wrapper
>     setattr(wrapper, attr, getattr(wrapped, attr))
> E   AttributeError: 'numpy.ufunc' object has no attribute '__module__'
>
> xref: scikit-image/scikit-image#3632
> <https://github.com/scikit-image/scikit-image/pull/3632>
>
> conda create --name py27 py=2 dask=1 --yes
> conda activate py27
> conda remove numpy --force --offline --yes
> pip uninstall numpy
> pip install numpy --pre
> python -c 'from dask import array as da'
>
> Traceback (most recent call last):
>   File "<string>", line 1, in <module>
>   File "/home/mark2/miniconda3/envs/py27/lib/python2.7/site-packages/dask/array/__init__.py", line 9, in <module>
>     from .routines import (take, choose, argwhere, where, coarsen, insert,
>   File "/home/mark2/miniconda3/envs/py27/lib/python2.7/site-packages/dask/array/routines.py", line 256, in <module>
>     @wraps(np.matmul)
>   File "/home/mark2/miniconda3/envs/py27/lib/python2.7/functools.py", line 33, in update_wrapper
>     setattr(wrapper, attr, getattr(wrapped, attr))
> AttributeError: 'numpy.ufunc' object has no attribute '__module__'
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/dask/dask/issues/4345>, or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AASszPY1bMIgSXYq4NsDvJyfqkp4HWhBks5u-5i4gaJpZM4Zl98F>
> .
>

Oh right, matmult is made a ufunc in 1.16

Resolving patch:
diff --git a/dask/array/routines.py b/dask/array/routines.py
--- a/dask/array/routines.py
+++ b/dask/array/routines.py
@@ -253,7 +253,7 @@ def vdot(a, b):
     return dot(a.conj().ravel(), b.ravel())
 
 
-@wraps(np.matmul)
+@safe_wraps(np.matmul)
 def matmul(a, b):
     a = asanyarray(a)
     b = asanyarray(b)


Test patch: