Skip to content

Commit 8880b04

Browse files
committed
Update for case with regular Float inputs, add tests
1 parent a805cc0 commit 8880b04

2 files changed

Lines changed: 38 additions & 2 deletions

File tree

src/amuse/units/trigo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
arccos = lambda x: numpy.arccos(x) | rad
1111
arctan = lambda x: numpy.arctan(x) | rad
1212
arctan2 = lambda x, y: numpy.arctan2(
13-
x.value_in(x.unit),
14-
y.value_in(x.unit),
13+
x.value_in(x.unit) if isinstance(x, quantities.Quantity) else x,
14+
y.value_in(x.unit) if isinstance(x, quantities.Quantity) else y,
1515
) | rad
1616

1717

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import pytest
2+
from amuse.support.testing import amusetest
3+
4+
from amuse.units import units
5+
from amuse.units.trigo import arctan2
6+
7+
8+
class TestsForIssue1180(amusetest.TestCase):
9+
10+
def test_arctan2_without_units(self):
11+
"Test when input has no units"
12+
x = 1.0
13+
y = 2.0
14+
result = arctan2(x, y).value_in(units.rad)
15+
assert result == pytest.approx(0.4636476, 1e-7)
16+
17+
def test_arctan2_with_units(self):
18+
"Test when input has units"
19+
x = 1.0 | units.m
20+
y = 2.0 | units.m
21+
result = arctan2(x, y).value_in(units.rad)
22+
assert result == pytest.approx(0.4636476, 1e-7)
23+
24+
def test_arctan2_with_units_and_no_units(self):
25+
"Test when input has units and no units (should fail)"
26+
x = 1.0 | units.m
27+
y = 2.0
28+
with pytest.raises(AttributeError):
29+
result = arctan2(x, y).value_in(units.rad)
30+
31+
def test_arctan2_with_different_units(self):
32+
"Test when input has different units"
33+
x = 1.0 | units.m
34+
y = 2.0e-3 | units.km
35+
result = arctan2(x, y).value_in(units.rad)
36+
assert result == pytest.approx(0.4636476, 1e-7)

0 commit comments

Comments
 (0)