summaryrefslogtreecommitdiff
path: root/numpy/lib/tests/test_function_base.py
diff options
context:
space:
mode:
authorSebastian Berg <sebastian@sipsolutions.net>2021-02-22 13:23:39 -0600
committerGitHub <noreply@github.com>2021-02-22 13:23:39 -0600
commit02d508c90a214e0aeaf78b4ad41a578e267dce12 (patch)
treef6cb2d3341806fe0266b88d25d86b80fe0e78de0 /numpy/lib/tests/test_function_base.py
parentd23d968fef1464407bcb1b28147dcfff133bced4 (diff)
parentaeae93b6c0042f6ed8f45205545985cc194f84f3 (diff)
downloadnumpy-02d508c90a214e0aeaf78b4ad41a578e267dce12.tar.gz
Merge pull request #18110 from mhvk/function-base-piecewise-refactor
API: make piecewise subclass safe using use zeros_like.
Diffstat (limited to 'numpy/lib/tests/test_function_base.py')
-rw-r--r--numpy/lib/tests/test_function_base.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py
index 4c7c0480c..afcb81eff 100644
--- a/numpy/lib/tests/test_function_base.py
+++ b/numpy/lib/tests/test_function_base.py
@@ -2399,6 +2399,14 @@ class TestPiecewise:
assert_array_equal(y, np.array([[-1., -1., -1.],
[3., 3., 1.]]))
+ def test_subclasses(self):
+ class subclass(np.ndarray):
+ pass
+ x = np.arange(5.).view(subclass)
+ r = piecewise(x, [x<2., x>=4], [-1., 1., 0.])
+ assert_equal(type(r), subclass)
+ assert_equal(r, [-1., -1., 0., 0., 1.])
+
class TestBincount: