Package: python3-skimage
Version: 0.14.1-2
Severity: serious
Affects: python3-ccdproc, python3-hipspy, python3-sunpy
Tags: patch
Control: forwarded -1 https://github.com/scikit-image/scikit-image/issues/3551

$ python3
Python 3.7.2rc1 (default, Dec 12 2018, 06:25:49) 
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import skimage
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/skimage/__init__.py", line 167, in 
<module>
    from .util.dtype import (img_as_float32,
  File "/usr/lib/python3/dist-packages/skimage/util/__init__.py", line 8, in 
<module>
    from .arraycrop import crop
  File "/usr/lib/python3/dist-packages/skimage/util/arraycrop.py", line 8, in 
<module>
    from numpy.lib.arraypad import _validate_lengths
ImportError: cannot import name '_validate_lengths' from 'numpy.lib.arraypad' 
(/usr/lib/python3/dist-packages/numpy/lib/arraypad.py)

This happens in the CI tests on a number of packages after the update of numpy 
(see "Affects").

Since `_validate_lengths` is an internal identifies by Python convention, the 
bug is clearly in skimage.

It is resolved in 

https://github.com/scikit-image/scikit-image/pull/3556

For convenience, a patch is attached.

Cheers

Ole
From: Egor Panfilov <egor.v.panfi...@gmail.com>
Date: Thu, 22 Nov 2018 22:16:02 +0200
Subject: Handle deprecation of numpy `_validate_lengths`

https://github.com/scikit-image/scikit-image/pull/3561
https://github.com/scikit-image/scikit-image/pull/3556
https://github.com/scikit-image/scikit-image/issues/3551
---
 skimage/util/arraycrop.py | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/skimage/util/arraycrop.py b/skimage/util/arraycrop.py
index e83a6c6..3787770 100644
--- a/skimage/util/arraycrop.py
+++ b/skimage/util/arraycrop.py
@@ -5,8 +5,15 @@ n-dimensional array.
 from __future__ import division, absolute_import, print_function
 
 import numpy as np
-from numpy.lib.arraypad import _validate_lengths
 
+# After numpy 1.15, a new backward compatible function have been implemented.
+# See https://github.com/numpy/numpy/pull/11966
+from distutils.version import LooseVersion as Version
+old_numpy = Version(np.__version__) < Version('1.16')
+if old_numpy:
+    from numpy.lib.arraypad import _validate_lengths
+else:
+    from numpy.lib.arraypad import _as_pairs
 
 __all__ = ['crop']
 
@@ -169,7 +176,10 @@ def crop(ar, crop_width, copy=False, order='K'):
         view of the input array.
     """
     ar = np.array(ar, copy=False)
-    crops = _validate_lengths(ar, crop_width)
+    if old_numpy:
+        crops = _validate_lengths(ar, crop_width)
+    else:
+        crops = _as_pairs(crop_width, ar.ndim, as_index=True)
     slices = tuple(slice(a, ar.shape[i] - b)
                    for i, (a, b) in enumerate(crops))
     if copy:

Reply via email to