summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2015-10-30 13:27:51 -0600
committerCharles Harris <charlesr.harris@gmail.com>2015-10-30 14:15:34 -0600
commitf0c9703bd4bbc8d31c6ef5d94c141ec766f33dbc (patch)
tree309e72836c8fc37f657e2825da27d0b6dbd89531
parentf428bce78c576f9f3d8f17f49b83a3c6f196bef3 (diff)
downloadnumpy-f0c9703bd4bbc8d31c6ef5d94c141ec766f33dbc.tar.gz
DEP: Remove FutureWarning from np.lib.split and go to future.
Previously an empty array resulting from split always had dimension 1-D. In Numpy 1.9 a FutureWarning was raised to notify users that it was planned to preserve the dimensions of empty arrays in a future numpy release. This removes the FutureWarning and implements preservation of dimensions. Note that there was a bug in numpy 1.9 and the dimensions of empty arrays was already preserved in some cases and no warning was issued. This PR fixes that inconsistency by preserving the dimensions in all cases rather than fixing the bug, as the dimension preserving behavior was already depended on by some users. See the discussion in gh-6575 about this change.
-rw-r--r--numpy/lib/shape_base.py11
-rw-r--r--numpy/lib/tests/test_shape_base.py30
2 files changed, 13 insertions, 28 deletions
diff --git a/numpy/lib/shape_base.py b/numpy/lib/shape_base.py
index b2beef0a8..615cf88f4 100644
--- a/numpy/lib/shape_base.py
+++ b/numpy/lib/shape_base.py
@@ -421,18 +421,9 @@ def array_split(ary, indices_or_sections, axis=0):
end = div_points[i + 1]
sub_arys.append(_nx.swapaxes(sary[st:end], axis, 0))
- # This "kludge" was introduced here to replace arrays shaped (0, 10)
- # or similar with an array shaped (0,).
- # There seems no need for this, so give a FutureWarning to remove later.
- if any(arr.size == 0 and arr.ndim != 1 for arr in sub_arys):
- warnings.warn("in the future np.array_split will retain the shape of "
- "arrays with a zero size, instead of replacing them by "
- "`array([])`, which always has a shape of (0,).",
- FutureWarning)
- sub_arys = _replace_zero_by_x_arrays(sub_arys)
-
return sub_arys
+
def split(ary,indices_or_sections,axis=0):
"""
Split an array into multiple sub-arrays.
diff --git a/numpy/lib/tests/test_shape_base.py b/numpy/lib/tests/test_shape_base.py
index 8ab72b9f9..3f05f80c0 100644
--- a/numpy/lib/tests/test_shape_base.py
+++ b/numpy/lib/tests/test_shape_base.py
@@ -103,21 +103,17 @@ class TestArraySplit(TestCase):
def test_integer_split_2D_rows(self):
a = np.array([np.arange(10), np.arange(10)])
- res = assert_warns(FutureWarning, array_split, a, 3, axis=0)
-
- # After removing the FutureWarning, the last should be zeros((0, 10))
- desired = [np.array([np.arange(10)]), np.array([np.arange(10)]),
- np.array([])]
- compare_results(res, desired)
+ res = array_split(a, 3, axis=0)
+ tgt = [np.array([np.arange(10)]), np.array([np.arange(10)]),
+ np.zeros((0, 10))]
+ compare_results(res, tgt)
assert_(a.dtype.type is res[-1].dtype.type)
# Same thing for manual splits:
- res = assert_warns(FutureWarning, array_split, a, [0, 1, 2], axis=0)
-
- # After removing the FutureWarning, the last should be zeros((0, 10))
- desired = [np.array([]), np.array([np.arange(10)]),
- np.array([np.arange(10)])]
- compare_results(res, desired)
+ res = array_split(a, [0, 1, 2], axis=0)
+ tgt = [np.zeros((0, 10)), np.array([np.arange(10)]),
+ np.array([np.arange(10)])]
+ compare_results(res, tgt)
assert_(a.dtype.type is res[-1].dtype.type)
def test_integer_split_2D_cols(self):
@@ -132,12 +128,10 @@ class TestArraySplit(TestCase):
""" This will fail if we change default axis
"""
a = np.array([np.arange(10), np.arange(10)])
- res = assert_warns(FutureWarning, array_split, a, 3)
-
- # After removing the FutureWarning, the last should be zeros((0, 10))
- desired = [np.array([np.arange(10)]), np.array([np.arange(10)]),
- np.array([])]
- compare_results(res, desired)
+ res = array_split(a, 3)
+ tgt = [np.array([np.arange(10)]), np.array([np.arange(10)]),
+ np.zeros((0, 10))]
+ compare_results(res, tgt)
assert_(a.dtype.type is res[-1].dtype.type)
# perhaps should check higher dimensions