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
10 changes: 6 additions & 4 deletions pyreason/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
print('PyReason initialized!')
print()

# Update cache status
cache_status['initialized'] = True
with open(cache_status_path, 'w') as file:
yaml.dump(cache_status, file)
# Update cache status (skip under test runners to keep repo file clean)
import sys
if 'pytest' not in sys.modules and 'unittest' not in sys.modules:
cache_status['initialized'] = True
with open(cache_status_path, 'w') as file:
yaml.dump(cache_status, file)
18 changes: 16 additions & 2 deletions pyreason/scripts/interpretation/interpretation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1973,8 +1973,22 @@ def _delete_node(node, neighbors, reverse_neighbors, nodes, interpretations_node
@numba.njit(cache=True)
def float_to_str(value):
number = int(value)
decimal = int(value % 1 * 1000)
float_str = f'{number}.{decimal}'
decimal = int(round(abs(value) % 1 * 1000))

# Manual zero-padding (numba may not support :03d in f-strings)
if decimal < 10:
decimal_str = f'00{decimal}'
elif decimal < 100:
decimal_str = f'0{decimal}'
else:
decimal_str = f'{decimal}'

# Handle negative values where int() truncates to 0 (e.g., -0.123)
if value < 0 and number == 0:
float_str = f'-{number}.{decimal_str}'
else:
float_str = f'{number}.{decimal_str}'

return float_str


Expand Down
18 changes: 16 additions & 2 deletions pyreason/scripts/interpretation/interpretation_fp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2091,8 +2091,22 @@ def _delete_node(node, neighbors, reverse_neighbors, nodes, interpretations_node
@numba.njit(cache=True)
def float_to_str(value):
number = int(value)
decimal = int(value % 1 * 1000)
float_str = f'{number}.{decimal}'
decimal = int(round(abs(value) % 1 * 1000))

# Manual zero-padding (numba may not support :03d in f-strings)
if decimal < 10:
decimal_str = f'00{decimal}'
elif decimal < 100:
decimal_str = f'0{decimal}'
else:
decimal_str = f'{decimal}'

# Handle negative values where int() truncates to 0 (e.g., -0.123)
if value < 0 and number == 0:
float_str = f'-{number}.{decimal_str}'
else:
float_str = f'{number}.{decimal_str}'

return float_str


Expand Down
18 changes: 16 additions & 2 deletions pyreason/scripts/interpretation/interpretation_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1973,8 +1973,22 @@ def _delete_node(node, neighbors, reverse_neighbors, nodes, interpretations_node
@numba.njit(cache=True)
def float_to_str(value):
number = int(value)
decimal = int(value % 1 * 1000)
float_str = f'{number}.{decimal}'
decimal = int(round(abs(value) % 1 * 1000))

# Manual zero-padding (numba may not support :03d in f-strings)
if decimal < 10:
decimal_str = f'00{decimal}'
elif decimal < 100:
decimal_str = f'0{decimal}'
else:
decimal_str = f'{decimal}'

# Handle negative values where int() truncates to 0 (e.g., -0.123)
if value < 0 and number == 0:
float_str = f'-{number}.{decimal_str}'
else:
float_str = f'{number}.{decimal_str}'

return float_str


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,11 +579,50 @@ def foo(ann, wts):

def test_float_to_str_and_str_to_int():
assert float_to_str(12.345) == "12.345"
assert float_to_str(3.0) == "3.0"
assert float_to_str(3.0) == "3.000"
assert str_to_int("123") == 123
assert str_to_int("-45") == -45


@pytest.mark.parametrize(
"value,expected",
[
(-3.456, "-3.456"),
(-0.123, "-0.123"),
(-1.0, "-1.000"),
],
)
def test_float_to_str_negative_values(value, expected):
"""BUG-102: negative floats must preserve correct decimal digits."""
assert float_to_str(value) == expected


@pytest.mark.parametrize(
"value,expected",
[
(3.001, "3.001"),
(0.009, "0.009"),
(5.050, "5.050"),
(0.0, "0.000"),
],
)
def test_float_to_str_zero_padding(value, expected):
"""BUG-103: leading zeros in fractional part must be preserved."""
assert float_to_str(value) == expected


@pytest.mark.parametrize(
"value,expected",
[
(-0.001, "-0.001"),
(-3.010, "-3.010"),
],
)
def test_float_to_str_negative_with_zero_padding(value, expected):
"""BUG-102 + BUG-103 combined: negative values with leading-zero decimals."""
assert float_to_str(value) == expected


@pytest.mark.parametrize(
"s,expected",
[("3.14", 3.14), ("42", 42.0), ("-2.5", -2.5)],
Expand Down