diff options
author | Sebastian Berg <sebastian@sipsolutions.net> | 2021-09-29 13:40:15 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-29 13:40:15 -0700 |
commit | 1cadccc6012124e38e02a78b39bf268123d272c1 (patch) | |
tree | 622c3d8df434d931041d21d6d06062ac009ecc5b /numpy | |
parent | 54959ec46bc53822e119da06809306540cf6a0e5 (diff) | |
parent | 1b892e0e3d7c82e906e68bf622c3bb2d215714d4 (diff) | |
download | numpy-1cadccc6012124e38e02a78b39bf268123d272c1.tar.gz |
Merge pull request #19843 from yashasvimisra2798/patch2
TST: Fix/Improve cast nonstandard bool to 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 d41d6dcc0..b0d8ff503 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) + |