Skip to content
This repository has been archived by the owner on Aug 31, 2018. It is now read-only.

Commit

Permalink
Merge pull request #83 from kmader/patch-1
Browse files Browse the repository at this point in the history
Label should warn not error if multiple chunks
  • Loading branch information
jakirkham committed Jun 26, 2018
2 parents 38fb0d9 + ad284e1 commit 8b58a39
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
3 changes: 2 additions & 1 deletion dask_ndmeasure/__init__.py
Expand Up @@ -13,6 +13,7 @@


import itertools
from warnings import warn

import numpy
import scipy.ndimage
Expand Down Expand Up @@ -208,7 +209,7 @@ def label(input, structure=None):
input = _compat._asarray(input)

if not all([len(c) == 1 for c in input.chunks]):
raise ValueError("``input`` must have 1 chunk in all dimensions.")
warn("``input`` does not have 1 chunk in all dimensions; it will be consolidated first", RuntimeWarning)

result = dask.delayed(scipy.ndimage.label)(input, structure)

Expand Down
16 changes: 6 additions & 10 deletions tests/test_core.py
Expand Up @@ -254,18 +254,14 @@ def test_label(shape, chunks, connectivity):

s = spnd.generate_binary_structure(a.ndim, connectivity)

if all([len(c) == 1 for c in d.chunks]):
a_l, a_nl = spnd.label(a, s)
d_l, d_nl = dask_ndmeasure.label(d, s)
a_l, a_nl = spnd.label(a, s)
d_l, d_nl = dask_ndmeasure.label(d, s)

assert a_nl == d_nl.compute()
assert a_nl == d_nl.compute()

assert a_l.dtype == d_l.dtype
assert a_l.shape == d_l.shape
assert np.allclose(np.array(a_l), np.array(d_l), equal_nan=True)
else:
with pytest.raises(ValueError):
dask_ndmeasure.label(d, s)
assert a_l.dtype == d_l.dtype
assert a_l.shape == d_l.shape
assert np.allclose(np.array(a_l), np.array(d_l), equal_nan=True)


@pytest.mark.parametrize(
Expand Down

0 comments on commit 8b58a39

Please sign in to comment.