Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/celpy/celtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
import logging
import re
from functools import reduce, wraps
from math import fsum
from math import fsum, trunc
from typing import (
Any,
Callable,
Expand Down Expand Up @@ -545,7 +545,7 @@ class IntType(int):
ValueError: overflow

>>> IntType(DoubleType(1.9))
IntType(2)
IntType(1)
>>> IntType(DoubleType(-123.456))
IntType(-123)
"""
Expand All @@ -562,7 +562,7 @@ def __new__(
# Used by protobuf.
return super().__new__(cls, cast(int, source.get(StringType("value"))))
elif isinstance(source, (float, DoubleType)):
convert = int64(round)
convert = int64(trunc)
elif isinstance(source, TimestampType):
convert = int64(lambda src: src.timestamp())
elif isinstance(source, (str, StringType)) and source[:2] in {"0x", "0X"}:
Expand Down Expand Up @@ -729,7 +729,7 @@ def __new__(
if isinstance(source, UintType):
return source
elif isinstance(source, (float, DoubleType)):
convert = uint64(round)
convert = uint64(trunc)
elif isinstance(source, TimestampType):
convert = uint64(lambda src: src.timestamp())
elif isinstance(source, (str, StringType)) and source[:2] in {"0x", "0X"}:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_celtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def test_double_type():
def test_int_type():
i_42 = IntType(42)
i_max = IntType(9223372036854775807)
assert IntType(DoubleType(1.9)) == IntType(2)
assert IntType(DoubleType(1.9)) == IntType(1)
assert IntType(DoubleType(-123.456)) == IntType(-123)
assert IntType(TimestampType("2009-02-13T23:31:30Z")) == 1234567890
assert IntType("0x2a") == 42
Expand Down Expand Up @@ -160,7 +160,7 @@ def test_int_type():
def test_uint_type():
u_42 = UintType(42)
u_max = UintType(18446744073709551615)
assert UintType(DoubleType(1.9)) == UintType(2)
assert UintType(DoubleType(1.9)) == UintType(1)
with pytest.raises(ValueError):
assert UintType(DoubleType(-123.456)) == UintType(-123)
assert UintType(TimestampType("2009-02-13T23:31:30Z")) == 1234567890
Expand Down
9 changes: 0 additions & 9 deletions tools/wip.toml
Original file line number Diff line number Diff line change
Expand Up @@ -239,16 +239,7 @@ string_true_uppercase = "@wip"
timestamp = "@wip"

[conversions.int]
double_half_neg = "@wip"
double_half_pos = "@wip"
double_int_min_range = "@wip"
double_truncate = "@wip"
double_truncate_neg = "@wip"

[conversions.uint]
double_half = "@wip"
double_truncate = "@wip"

[dynamic.any]
literal = "@wip"

Expand Down
Loading