summaryrefslogtreecommitdiff
path: root/numpy/lib/tests/test_function_base.py
diff options
context:
space:
mode:
authorMarten van Kerkwijk <mhvk@astro.utoronto.ca>2021-01-03 11:11:15 -0500
committerMarten van Kerkwijk <mhvk@astro.utoronto.ca>2021-02-22 10:37:32 -0500
commitaeae93b6c0042f6ed8f45205545985cc194f84f3 (patch)
tree404f3e80245dabae30b884cbf64b4821b8bc0451 /numpy/lib/tests/test_function_base.py
parent68e4d56eb9b539cccd582de7e7fb09c373d37609 (diff)
downloadnumpy-aeae93b6c0042f6ed8f45205545985cc194f84f3.tar.gz
API: make piecewise subclass safe using use zeros_like.
Subclass input of piecewise was already respected, so it seems more logical to ensure the output is the same subclass (possibly just an oversight that it was not done before).
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: