diff options
author | Juan Luis Cano RodrÃguez <juanlu001@gmail.com> | 2014-06-07 21:52:29 +0200 |
---|---|---|
committer | Juan Luis Cano RodrÃguez <juanlu001@gmail.com> | 2014-06-08 15:40:23 +0200 |
commit | 292b9ff538ea4950c7380c76cf65d1a5b108b75c (patch) | |
tree | 2f1876657ae20298c217e9787e86857f9abd213b /numpy/lib/tests/test_function_base.py | |
parent | db710cefeecf51d6253e421712726c1506a6f65b (diff) | |
download | numpy-292b9ff538ea4950c7380c76cf65d1a5b108b75c.tar.gz |
BUG: Fixed piecewise function for 0d input
When `x` has more than one element the condlist `[True, False]`
is being made equivalent to `[[True, False]]`, which is correct.
However, when `x` is zero dimensional the expected condlist is
`[[True], [False]]`: this commit addresses the issue. Besides,
the documentation stated that there could be undefined values
but actually these are 0 by default: using `nan` would be desirable,
but for the moment the docs were corrected. Closes #331.
Diffstat (limited to 'numpy/lib/tests/test_function_base.py')
-rw-r--r-- | numpy/lib/tests/test_function_base.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index cb4d6626d..ee38b3573 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -1487,6 +1487,7 @@ class TestPiecewise(TestCase): x = piecewise([0, 0], [[False, True]], [lambda x:-1]) assert_array_equal(x, [0, -1]) + def test_two_conditions(self): x = piecewise([1, 2], [[True, False], [False, True]], [3, 4]) assert_array_equal(x, [3, 4]) @@ -1505,6 +1506,15 @@ class TestPiecewise(TestCase): assert_(y.ndim == 0) assert_(y == 0) + x = 5 + y = piecewise(x, [[True], [False]], [1, 0]) + assert_(y.ndim == 0) + assert_(y == 1) + + def test_0d_comparison(self): + x = 3 + y = piecewise(x, [x <= 3, x > 3], [4, 0]) + class TestBincount(TestCase): def test_simple(self): |