summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBas van Beek <b.f.van.beek@vu.nl>2021-08-31 16:38:14 +0200
committerBas van Beek <b.f.van.beek@vu.nl>2021-08-31 17:42:00 +0200
commit5d86d8c9cc70f87b4aab10682d101acd8c4fb781 (patch)
tree8565f9cc27dc7a61751513a8c1e95f477acfac2c
parent42483387d0bdfce0b48db94400054ad16bfd9ef1 (diff)
downloadnumpy-5d86d8c9cc70f87b4aab10682d101acd8c4fb781.tar.gz
TST: Add tests for `np.floating.is_integer`
-rw-r--r--numpy/core/tests/test_scalar_methods.py22
-rw-r--r--numpy/typing/tests/data/fail/scalars.py1
2 files changed, 22 insertions, 1 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()
diff --git a/numpy/typing/tests/data/fail/scalars.py b/numpy/typing/tests/data/fail/scalars.py
index 099418e67..94fe3f71e 100644
--- a/numpy/typing/tests/data/fail/scalars.py
+++ b/numpy/typing/tests/data/fail/scalars.py
@@ -87,7 +87,6 @@ round(c8) # E: No overload variant
c8.__getnewargs__() # E: Invalid self argument
f2.__getnewargs__() # E: Invalid self argument
-f2.is_integer() # E: Invalid self argument
f2.hex() # E: Invalid self argument
np.float16.fromhex("0x0.0p+0") # E: Invalid self argument
f2.__trunc__() # E: Invalid self argument