From 1e40d4e417c8cd4c07201d1ee38097570e5958c5 Mon Sep 17 00:00:00 2001 From: Gil Forsyth Date: Wed, 11 Oct 2023 16:05:37 -0400 Subject: [PATCH] fix(datatypes): correct unsigned integer bounds they were off by an order of magnitude. --- ibis/expr/datatypes/core.py | 2 +- ibis/expr/datatypes/tests/test_cast.py | 2 +- ibis/expr/datatypes/tests/test_core.py | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/ibis/expr/datatypes/core.py b/ibis/expr/datatypes/core.py index fbae85cbcce2..44e7d571fd39 100644 --- a/ibis/expr/datatypes/core.py +++ b/ibis/expr/datatypes/core.py @@ -653,7 +653,7 @@ def largest(self): @property def bounds(self): - exp = self.nbytes * 8 - 1 + exp = self.nbytes * 8 upper = 1 << exp return Bounds(lower=0, upper=upper) diff --git a/ibis/expr/datatypes/tests/test_cast.py b/ibis/expr/datatypes/tests/test_cast.py index eff2a718b27a..fbfc36978fcf 100644 --- a/ibis/expr/datatypes/tests/test_cast.py +++ b/ibis/expr/datatypes/tests/test_cast.py @@ -21,7 +21,6 @@ (dt.uint32, dt.Decimal(12, 2)), (dt.uint32, dt.float32), (dt.uint32, dt.float64), - (dt.uint64, dt.int64), (dt.Interval("s"), dt.Interval("s")), ], ) @@ -37,6 +36,7 @@ def test_implicitly_castable_primitives(source, target): (dt.int32, dt.uint16), (dt.uint64, dt.int16), (dt.uint64, dt.uint16), + (dt.uint64, dt.int64), (dt.Decimal(12, 2), dt.int32), (dt.timestamp, dt.boolean), (dt.Interval("s"), dt.Interval("ns")), diff --git a/ibis/expr/datatypes/tests/test_core.py b/ibis/expr/datatypes/tests/test_core.py index 37fcbcb386fc..8851abd20f2b 100644 --- a/ibis/expr/datatypes/tests/test_core.py +++ b/ibis/expr/datatypes/tests/test_core.py @@ -75,6 +75,23 @@ def test_dtype_from_classes(klass, expected): assert dt.dtype(klass) == expected +@pytest.mark.parametrize( + ("uklass", "klass"), + [ + (dt.UInt64, dt.Int64), + (dt.UInt32, dt.Int32), + (dt.UInt16, dt.Int16), + (dt.UInt8, dt.Int8), + ], +) +def test_signed_unsigned_bounds(uklass, klass): + unsigned = dt.dtype(uklass) + signed = dt.dtype(klass) + assert unsigned.bounds.upper > signed.bounds.upper + assert unsigned.bounds.lower == 0 + assert signed.bounds.lower < 0 + + class FooStruct: a: dt.int16 b: dt.int32