MCPcopy Create free account
hub / github.com/numpy/numpy / test_preserve_subclass

Method test_preserve_subclass

numpy/lib/tests/test_shape_base.py:123–139  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

121 [[27, 30, 33], [36, 39, 42], [45, 48, 51]])
122
123 def test_preserve_subclass(self):
124 def double(row):
125 return row * 2
126
127 class MyNDArray(np.ndarray):
128 pass
129
130 m = np.array([[0, 1], [2, 3]]).view(MyNDArray)
131 expected = np.array([[0, 2], [4, 6]]).view(MyNDArray)
132
133 result = apply_along_axis(double, 0, m)
134 assert_(isinstance(result, MyNDArray))
135 assert_array_equal(result, expected)
136
137 result = apply_along_axis(double, 1, m)
138 assert_(isinstance(result, MyNDArray))
139 assert_array_equal(result, expected)
140
141 def test_subclass(self):
142 class MinimalSubclass(np.ndarray):

Callers

nothing calls this directly

Calls 4

apply_along_axisFunction · 0.90
assert_Function · 0.90
assert_array_equalFunction · 0.90
viewMethod · 0.45

Tested by

no test coverage detected