Skip to content

Commit

Permalink
fix(datatypes): correct unsigned integer bounds
Browse files Browse the repository at this point in the history
they were off by an order of magnitude.
  • Loading branch information
gforsyth authored and cpcloud committed Oct 12, 2023
1 parent 7e1ece7 commit 1e40d4e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ibis/expr/datatypes/core.py
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion ibis/expr/datatypes/tests/test_cast.py
Expand Up @@ -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")),
],
)
Expand All @@ -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")),
Expand Down
17 changes: 17 additions & 0 deletions ibis/expr/datatypes/tests/test_core.py
Expand Up @@ -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
Expand Down

0 comments on commit 1e40d4e

Please sign in to comment.