Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Backport gh 6361 #6376

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 27, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion numpy/lib/shape_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ def array_split(ary, indices_or_sections, 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 sub_arys[-1].size == 0 and sub_arys[-1].ndim != 1:
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,).",
Expand Down
9 changes: 9 additions & 0 deletions numpy/lib/tests/test_shape_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ def test_integer_split_2D_rows(self):
compare_results(res, desired)
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)
assert_(a.dtype.type is res[-1].dtype.type)

def test_integer_split_2D_cols(self):
a = np.array([np.arange(10), np.arange(10)])
res = array_split(a, 3, axis=-1)
Expand Down