Repository: cupy/cupy

Issue:
Rename `scipy.ndimage.sum` to `scipy.ndimage.sum_labels`
SciPy 1.6.0 changed the API: https://github.com/scipy/scipy/pull/12242


Discussion:
It's worth noting the old name was hung onto as an alias. Maybe worth doing the same thing in CuPy?

Resolving patch:
diff --git a/cupyx/scipy/ndimage/__init__.py b/cupyx/scipy/ndimage/__init__.py
--- a/cupyx/scipy/ndimage/__init__.py
+++ b/cupyx/scipy/ndimage/__init__.py
@@ -38,6 +38,7 @@
 
 from cupyx.scipy.ndimage.measurements import label  # NOQA
 from cupyx.scipy.ndimage.measurements import sum  # NOQA
+from cupyx.scipy.ndimage.measurements import sum_labels  # NOQA
 from cupyx.scipy.ndimage.measurements import mean  # NOQA
 from cupyx.scipy.ndimage.measurements import variance  # NOQA
 from cupyx.scipy.ndimage.measurements import standard_deviation  # NOQA
diff --git a/cupyx/scipy/ndimage/measurements.py b/cupyx/scipy/ndimage/measurements.py
--- a/cupyx/scipy/ndimage/measurements.py
+++ b/cupyx/scipy/ndimage/measurements.py
@@ -361,7 +361,7 @@ def calc_var_with_intermediate_float(input):
                                     out) / count
 
 
-def sum(input, labels=None, index=None):
+def sum_labels(input, labels=None, index=None):
     """Calculates the sum of the values of an n-D image array, optionally
        at specified sub-regions.
 
@@ -376,7 +376,7 @@ def sum(input, labels=None, index=None):
        sum (cupy.ndarray): sum of values, for each sub-region if
        `labels` and `index` are specified.
 
-    .. seealso:: :func:`scipy.ndimage.sum`
+    .. seealso:: :func:`scipy.ndimage.sum_labels`
     """
     if not isinstance(input, cupy.ndarray):
         raise TypeError('input must be cupy.ndarray')
@@ -425,6 +425,31 @@ def sum(input, labels=None, index=None):
     return _ndimage_sum_kernel(input, labels, index, index.size, out)
 
 
+def sum(input, labels=None, index=None):
+    """Calculates the sum of the values of an n-D image array, optionally
+       at specified sub-regions.
+
+    Args:
+        input (cupy.ndarray): Nd-image data to process.
+        labels (cupy.ndarray or None): Labels defining sub-regions in `input`.
+            If not None, must be same shape as `input`.
+        index (cupy.ndarray or None): `labels` to include in output. If None
+            (default), all values where `labels` is non-zero are used.
+
+    Returns:
+       sum (cupy.ndarray): sum of values, for each sub-region if
+       `labels` and `index` are specified.
+
+    Notes:
+        This is an alias for `cupyx.scipy.ndimage.sum_labels` kept for
+        backwards compatibility reasons. For new code please prefer
+        `sum_labels`.
+
+    .. seealso:: :func:`scipy.ndimage.sum`
+    """
+    return sum_labels(input, labels, index)
+
+
 def mean(input, labels=None, index=None):
     """Calculates the mean of the values of an n-D image array, optionally
        at specified sub-regions.


Test patch:
diff --git a/tests/cupyx_tests/scipy_tests/ndimage_tests/test_measurements.py b/tests/cupyx_tests/scipy_tests/ndimage_tests/test_measurements.py
--- a/tests/cupyx_tests/scipy_tests/ndimage_tests/test_measurements.py
+++ b/tests/cupyx_tests/scipy_tests/ndimage_tests/test_measurements.py
@@ -11,10 +11,18 @@
 import cupyx.scipy.ndimage  # NOQA
 
 try:
+    import scipy
     import scipy.ndimage  # NOQA
+    scipy_version = numpy.lib.NumpyVersion(scipy.__version__)
 except ImportError:
+    scipy_version = numpy.lib.NumpyVersion('0.0.0')
     pass
 
+stats_ops = ['sum', 'mean', 'variance', 'standard_deviation', 'center_of_mass']
+if scipy_version >= '1.6.0':
+    # 'scipy 1.6 added a copy of sum under the name sum_labels'
+    stats_ops += ['sum_labels']
+
 
 def _generate_binary_structure(rank, connectivity):
     if connectivity < 1:
@@ -105,7 +113,7 @@ def test_label_swirl(self, xp, scp):
 
 @testing.gpu
 @testing.parameterize(*testing.product({
-    'op': ['sum', 'mean', 'variance', 'standard_deviation', 'center_of_mass'],
+    'op': stats_ops,
 }))
 @testing.with_requires('scipy')
 class TestStats: