From f8a47608ccc6a9d7b4e153f006c332f6ac8ef6e4 Mon Sep 17 00:00:00 2001 From: chenyu Date: Sun, 14 Jul 2024 15:31:37 -0400 Subject: [PATCH] test dtype.min and dtype.max (#5479) compared with np.iinfo for integer dtype --- test/test_dtype.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/test_dtype.py b/test/test_dtype.py index 04c6f365..72d619d2 100644 --- a/test/test_dtype.py +++ b/test/test_dtype.py @@ -347,6 +347,20 @@ class TestHelpers(unittest.TestCase): with self.assertRaises(RuntimeError): dtypes.from_py({}) with self.assertRaises(RuntimeError): dtypes.from_py(set()) + def test_dtype_range(self): + for dt in core_dtypes: + if dtypes.is_float(dt): + np.testing.assert_equal(dtypes.min(dt), -math.inf) + np.testing.assert_equal(dtypes.max(dt), math.inf) + elif dtypes.is_int(dt): + info = np.iinfo(_to_np_dtype(dt)) + np.testing.assert_equal(dtypes.min(dt), info.min) + np.testing.assert_equal(dtypes.max(dt), info.max) + else: + assert dt == dtypes.bool, dt + np.testing.assert_equal(dtypes.min(dt), False) + np.testing.assert_equal(dtypes.max(dt), True) + class TestTypeSpec(unittest.TestCase): def setUp(self): self.old_default_int, self.old_default_float = dtypes.default_int, dtypes.default_float