diff options
| author | Yashasvi Misra <yashasvimisra_bh@srmuniv.edu.in> | 2021-09-07 17:56:06 +0000 |
|---|---|---|
| committer | Sebastian Berg <sebastian@sipsolutions.net> | 2021-09-29 13:46:29 -0500 |
| commit | 1b892e0e3d7c82e906e68bf622c3bb2d215714d4 (patch) | |
| tree | 87d2d813d36c1c70854ebab1974abba7955e17e6 /numpy | |
| parent | 1fe57b2427e20f466c254ed6a98a014d9a9e574e (diff) | |
| download | numpy-1b892e0e3d7c82e906e68bf622c3bb2d215714d4.tar.gz | |
TST: Fix/Improve nonstandard bool to cast numeric test
Diffstat (limited to 'numpy')
| -rw-r--r-- | numpy/core/tests/test_casting_unittests.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/numpy/core/tests/test_casting_unittests.py b/numpy/core/tests/test_casting_unittests.py index a13e807e2..678faad25 100644 --- a/numpy/core/tests/test_casting_unittests.py +++ b/numpy/core/tests/test_casting_unittests.py @@ -699,9 +699,14 @@ class TestCasting: else: assert_array_equal(expected, arr_NULLs.astype(dtype)) - def test_float_to_bool(self): - # test case corresponding to gh-19514 - # simple test for casting bool_ to float16 - res = np.array([0, 3, -7], dtype=np.int8).view(bool) + @pytest.mark.parametrize("dtype", + np.typecodes["AllInteger"] + np.typecodes["AllFloat"]) + def test_nonstandard_bool_to_other(self, dtype): + # simple test for casting bool_ to numeric types, which should not + # expose the detail that NumPy bools can sometimes take values other + # than 0 and 1. See also gh-19514. + nonstandard_bools = np.array([0, 3, -7], dtype=np.int8).view(bool) + res = nonstandard_bools.astype(dtype) expected = [0, 1, 1] assert_array_equal(res, expected) + |
