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

Major changes for numpy compatibility and overhaul the stubs file #33

Merged
merged 6 commits into from
Jan 31, 2025
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: 3 additions & 5 deletions test/cython/test_with_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def deep_equal(a: WithUnit, b: WithUnit) -> bool:
bool, whether a and b have exactly the same properties.
"""
if isinstance(a, ValueArray):
if not np.array_equal(a, b):
if not np.array_equal(a, b): # type: ignore[arg-type]
return False
else:
if a != b:
Expand Down Expand Up @@ -473,10 +473,8 @@ def test_non_zero() -> None:


def test_numpy_method_is_finite() -> None:
with pytest.raises(TypeError):
np.isfinite(val([], units=m))
with pytest.raises(TypeError):
np.isfinite(val([1], units=m))
assert np.all(np.isfinite(val([], units=m)))
assert np.all(np.isfinite(val([1], units=m)))

v = val([2, 3, -2, float('nan'), float('inf')], conv(1, 2, 3, 4))
assert np.array_equal(np.isfinite(v), [True, True, True, False, False])
Expand Down
6 changes: 3 additions & 3 deletions test/test_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,14 @@ def test_hash() -> None:
def test_numpy_sqrt() -> None:
from tunits.units import m, km, cm

u: Value = np.sqrt(8 * km * m) - cm # type: ignore[assignment]
u: Value = np.sqrt(8 * km * m) - cm
v = 8943.27191 * cm
assert np.isclose(u / v, 1)

u = np.sqrt(8 * km / m) # type: ignore[assignment]
u = np.sqrt(8 * km / m)
assert np.isclose(u, 89.4427191)

u = np.sqrt((8 * km / m).in_base_units()) # type: ignore[assignment]
u = np.sqrt((8 * km / m).in_base_units())
assert np.isclose(u, 89.4427191)


Expand Down
Loading