8000 BUG: Fix crash on 0d return value in apply_along_axis by eric-wieser · Pull Request #8441 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: Fix crash on 0d return value in apply_along_axis #8441

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 8 commits into from
Feb 12, 2017
Prev Previous commit
Next Next commit
TST: Verify apply_along_axis now works on masked arrays
Note that this is not a full subsitute for np.ma.apply_along_axis,
as that allows functions to return a mix of np.ma.masked and scalars
  • Loading branch information
eric-wieser committed Feb 11, 2017
commit ff9c363bb729a37f09c63937e45d5870501bfbad
14 changes: 14 additions & 0 deletions numpy/lib/tests/test_shape_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,20 @@ class MinimalSubclass(np.ndarray):
self.test_0d_array(MinimalSubclass)
self.test_axis_insertion(MinimalSubclass)

def test_axis_insertion_ma(self):
def f1to2(x):
"""produces an assymmetric non-square matrix from x"""
assert_equal(x.ndim, 1)
res = x[::-1] * x[1:,None]
return np.ma.masked_where(res%5==0, res)
a = np.arange(6*3).reshape((6, 3))
res = apply_along_axis(f1to2, 0, a)
assert_(isinstance(res, np.ma.masked_array))
assert_equal(res.ndim, 3)
assert_array_equal(res[:,:,0].mask, f1to2(a[:,0]).mask)
assert_array_equal(res[:,:,1].mask, f1to2(a[:,1]).mask)
assert_array_equal(res[:,:,2].mask, f1to2(a[:,2]).mask)

def test_tuple_func1d(self):
def sample_1d(x):
return x[1], x[0]
Expand Down
0