Skip to content

Commit 5d86d8c

Browse files
author
Bas van Beek
committed
TST: Add tests for np.floating.is_integer
1 parent 4248338 commit 5d86d8c

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

numpy/core/tests/test_scalar_methods.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,25 @@ def test_roundtrip(self, ftype, frac_vals, exp_vals):
102102
pytest.skip("longdouble too small on this platform")
103103

104104
assert_equal(nf / df, f, "{}/{}".format(n, d))
105+
106+
107+
@pytest.mark.parametrize("code", np.typecodes["Float"])
108+
class TestIsInteger:
109+
@pytest.mark.parametrize("str_value", ["inf", "nan"])
110+
def test_special(self, code: str, str_value: str) -> None:
111+
cls = np.dtype(code).type
112+
value = cls(str_value)
113+
assert not value.is_integer()
114+
115+
def test_true(self, code: str) -> None:
116+
float_array = np.arange(-5, 5).astype(code)
117+
for value in float_array:
118+
assert value.is_integer()
119+
120+
def test_false(self, code: str) -> None:
121+
float_array = np.arange(-5, 5).astype(code)
122+
float_array *= 1.1
123+
for value in float_array:
124+
if value == 0:
125+
continue
126+
assert not value.is_integer()

numpy/typing/tests/data/fail/scalars.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ def func(a: np.float32) -> None: ...
8787

8888
c8.__getnewargs__() # E: Invalid self argument
8989
f2.__getnewargs__() # E: Invalid self argument
90-
f2.is_integer() # E: Invalid self argument
9190
f2.hex() # E: Invalid self argument
9291
np.float16.fromhex("0x0.0p+0") # E: Invalid self argument
9392
f2.__trunc__() # E: Invalid self argument

0 commit comments

Comments
 (0)