8000 BUG: Fix apply_along_axis() for when func1d() returns a non-ndarray (… · numpy/numpy@b1b67d6 · GitHub
[go: up one dir, main page]

Skip to content

Commit b1b67d6

Browse files
bennyrowlandcharris
authored andcommitted
BUG: Fix apply_along_axis() for when func1d() returns a non-ndarray (#8426)
* BUG: Closes issue #8419 Fixes issue in apply_along_axis() where func1d() returns a non ndarray * BUG: Fix apply_along_axis() when func1d() returns a non-ndarray Closes issue #8419. Fixes issue in apply_along_axis() where func1d() returns a non ndarray by calling asanyarray() on result. This commit fixes a too long line in the test case.
1 parent 3add9ed commit b1b67d6

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

numpy/lib/shape_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def apply_along_axis(func1d, axis, arr, *args, **kwargs):
127127
ind[n] = 0
128128
n -= 1
129129
i.put(indlist, ind)
130-
res = func1d(arr[tuple(i.tolist())], *args, **kwargs)
130+
res = asanyarray(func1d(arr[tuple(i.tolist())], *args, **kwargs))
131131
outarr[tuple(i.tolist())] = res
132132
k += 1
133133
if res.shape == ():

numpy/lib/tests/test_shape_base.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ class MinimalSubclass(np.ndarray):
5858
assert isinstance(res, MinimalSubclass)
5959
assert_array_equal(res, np.array([6, 6, 6]).view(MinimalSubclass))
6060

61+
def test_tuple_func1d(self):
62+
def sample_1d(x):
63+
return x[1], x[0]
64+
res = np.apply_along_axis(sample_1d, 1, np.array([[1, 2], [3, 4]]))
65+
assert_array_equal(res, np.array([[2, 1], [4, 3]]))
66+
6167

6268
class TestApplyOverAxes(TestCase):
6369
def test_simple(self):

0 commit comments

Comments
 (0)
0