Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add macos-latest to ci pipeline #229

Merged
merged 4 commits into from
Oct 2, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
fix(truncate): add machine-consistent behaviour for undefined NaN error
Closes #280
ljgray committed Oct 2, 2024
commit dab26bebfff84c6b374bbf051fe3ede197c57b07
14 changes: 14 additions & 0 deletions caput/truncate.pyx
Original file line number Diff line number Diff line change
@@ -64,7 +64,14 @@ def bit_truncate_float(float val, float err):
-------
val
The truncated value.
Raises
------
ValueError
If `err` is a NaN.
"""
if err != err:
raise ValueError(f"Error {err} is invalid.")

return _bit_truncate_float(val, err)

@@ -83,7 +90,14 @@ def bit_truncate_double(double val, double err):
-------
val
The truncated value.
Raises
------
ValueError
If `err` is a NaN.
"""
if err != err:
raise ValueError(f"Error {err} is invalid.")

return _bit_truncate_double(val, err)

15 changes: 9 additions & 6 deletions tests/test_truncate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
import pytest

from caput import truncate

@@ -58,21 +59,23 @@ def test_truncate_float():
assert truncate.bit_truncate_double(32.121, -1) == 0
assert truncate.bit_truncate_float(32.121, np.inf) == 0
assert truncate.bit_truncate_double(32.121, np.inf) == 0
assert truncate.bit_truncate_float(32.121, np.nan) == 0
assert truncate.bit_truncate_double(32.121, np.nan) == 0
assert truncate.bit_truncate_float(np.inf, 1) == np.inf
assert truncate.bit_truncate_double(np.inf, 1) == np.inf
assert np.isnan(truncate.bit_truncate_float(np.nan, 1))
assert np.isnan(truncate.bit_truncate_double(np.nan, 1))

assert truncate.bit_truncate_float(np.inf, np.inf) == 0
assert truncate.bit_truncate_double(np.inf, np.inf) == 0
assert truncate.bit_truncate_float(np.inf, np.nan) == 0
assert truncate.bit_truncate_double(np.inf, np.nan) == 0
assert truncate.bit_truncate_float(np.nan, np.nan) == 0
assert truncate.bit_truncate_double(np.nan, np.nan) == 0
assert truncate.bit_truncate_float(np.nan, np.inf) == 0
assert truncate.bit_truncate_double(np.nan, np.inf) == 0

# Test that an error is raised when `err` is `NaN`
with pytest.raises(ValueError):
truncate.bit_truncate_float(32.121, np.nan)

with pytest.raises(ValueError):
truncate.bit_truncate_double(32.121, np.nan)


def test_truncate_array():
assert (