From 92433b29619783fb1bc064024ca06666b6307dd0 Mon Sep 17 00:00:00 2001 From: Juan Nunez-Iglesias Date: Wed, 7 Jan 2015 11:40:45 +1100 Subject: [PATCH] Fix and test 0-end bug in crop --- skimage/util/arraypad.py | 2 +- skimage/util/tests/test_arraypad.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/skimage/util/arraypad.py b/skimage/util/arraypad.py index 49f89e3d..cce40dc8 100644 --- a/skimage/util/arraypad.py +++ b/skimage/util/arraypad.py @@ -1530,7 +1530,7 @@ def crop(ar, crop_width, copy=False, order='K'): """ ar = np.array(ar, copy=False) crops = _validate_lengths(ar, crop_width) - slices = tuple([slice(a, -b) for a, b in crops]) + slices = [slice(a, ar.shape[i] - b) for i, (a, b) in enumerate(crops)] if copy: cropped = np.copy(ar[slices], order=order) else: diff --git a/skimage/util/tests/test_arraypad.py b/skimage/util/tests/test_arraypad.py index 4d990d0a..d6f993f9 100644 --- a/skimage/util/tests/test_arraypad.py +++ b/skimage/util/tests/test_arraypad.py @@ -1081,5 +1081,11 @@ def test_copy_crop(): assert np.may_share_memory(arr, out1) +def test_zero_crop(): + arr = np.arange(45).reshape(9, 5) + out = crop(arr, 0) + assert out.shape == (9, 5) + + if __name__ == "__main__": np.testing.run_module_suite()