diff options
| author | Bas van Beek <b.f.van.beek@vu.nl> | 2021-08-31 16:38:14 +0200 |
|---|---|---|
| committer | Bas van Beek <b.f.van.beek@vu.nl> | 2021-08-31 17:42:00 +0200 |
| commit | 5d86d8c9cc70f87b4aab10682d101acd8c4fb781 (patch) | |
| tree | 8565f9cc27dc7a61751513a8c1e95f477acfac2c /numpy/core | |
| parent | 42483387d0bdfce0b48db94400054ad16bfd9ef1 (diff) | |
| download | numpy-5d86d8c9cc70f87b4aab10682d101acd8c4fb781.tar.gz | |
TST: Add tests for `np.floating.is_integer`
Diffstat (limited to 'numpy/core')
| -rw-r--r-- | numpy/core/tests/test_scalar_methods.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/numpy/core/tests/test_scalar_methods.py b/numpy/core/tests/test_scalar_methods.py index 3693bba59..7bad6bebf 100644 --- a/numpy/core/tests/test_scalar_methods.py +++ b/numpy/core/tests/test_scalar_methods.py @@ -102,3 +102,25 @@ class TestAsIntegerRatio: pytest.skip("longdouble too small on this platform") assert_equal(nf / df, f, "{}/{}".format(n, d)) + + +@pytest.mark.parametrize("code", np.typecodes["Float"]) +class TestIsInteger: + @pytest.mark.parametrize("str_value", ["inf", "nan"]) + def test_special(self, code: str, str_value: str) -> None: + cls = np.dtype(code).type + value = cls(str_value) + assert not value.is_integer() + + def test_true(self, code: str) -> None: + float_array = np.arange(-5, 5).astype(code) + for value in float_array: + assert value.is_integer() + + def test_false(self, code: str) -> None: + float_array = np.arange(-5, 5).astype(code) + float_array *= 1.1 + for value in float_array: + if value == 0: + continue + assert not value.is_integer() |
