10000 Merge pull request #6371 from seberg/pr-5771 · numpy/numpy@ea289ee · GitHub
[go: up one dir, main page]

Skip to content

Commit ea289ee

Browse files
committed
Merge pull request #6371 from seberg/pr-5771
BUG: Make sure warning for array split is always applied
2 parents 41afcc3 + f29c387 commit ea289ee

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

numpy/lib/shape_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ def array_split(ary, indices_or_sections, axis=0):
424424
# This "kludge" was introduced here to replace arrays shaped (0, 10)
425425
# or similar with an array shaped (0,).
426426
# There seems no need for this, so give a FutureWarning to remove later.
427-
if sub_arys[-1].size == 0 and sub_arys[-1].ndim != 1:
427+
if any(arr.size == 0 and arr.ndim != 1 for arr in sub_arys):
428428
warnings.warn("in the future np.array_split will retain the shape of "
429429
"arrays with a zero size, instead of replacing them by "
430430
"`array([])`, which always has a shape of (0,).",

numpy/lib/tests/test_shape_base.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,15 @@ def test_integer_split_2D_rows(self):
111111
compare_results(res, desired)
112112
assert_(a.dtype.type is res[-1].dtype.type)
113113

114+
# Same thing for manual splits:
115+
res = assert_warns(FutureWarning, array_split, a, [0, 1, 2], axis=0)
116+
117+
# After removing the FutureWarning, the last should be zeros((0, 10))
118+
desired = [np.array([]), np.array([np.arange(10)]),
119+
np.array([np.arange(10)])]
120+
compare_results(res, desired)
121+
assert_(a.dtype.type is res[-1].dtype.type)
122+
114123
def test_integer_split_2D_cols(self):
115124
a = np.array([np.arange(10), np.arange(10)])
116125
res = array_split(a, 3, axis=-1)

0 commit comments

Comments
 (0)
0