Skip to content

Commit

Permalink
build: skip plum 2.4.2 (#126)
Browse files Browse the repository at this point in the history
* build: skip plum 2.4.2
* test: add pylint ignore
* test: change spherical
  • Loading branch information
nstarman authored Jun 19, 2024
1 parent 97dffd6 commit 3622eed
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"jax",
"jaxlib",
"jaxtyping",
"plum-dispatch>=2.3.3",
"plum-dispatch>=2.3.3,!=2.4.2",
"quax>=0.0.3",
"quaxed >= 0.4",
"unxt >= 0.10",
Expand Down Expand Up @@ -218,6 +218,7 @@
"protected-access", # handled by ruff
"redefined-builtin", # handled by ruff
"too-many-function-args", # plum-dispatch
"unexpected-keyword-arg", # plum-dispatch
"unnecessary-ellipsis", # I like my ellipses in ABCs and Protocols
"unsubscriptable-object", # handled by mypy
"unused-argument", # handled by ruff
Expand Down
36 changes: 22 additions & 14 deletions tests/test_d3.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def test_neg_compare_apy(
apyc.CartesianRepresentation
)
apycart = -apyvector.represent_as(apyc.CartesianRepresentation)
assert np.allclose(cart.x, apycart.x, atol=5e-7)
assert np.allclose(cart.y, apycart.y, atol=5e-7)
assert np.allclose(cart.x, apycart.x, atol=1e-6) # TODO: better agreement
assert np.allclose(cart.y, apycart.y, atol=1e-5) # TODO: better agreement
assert np.allclose(cart.z, apycart.z, atol=5e-7)

# # Try finding the poles
Expand Down Expand Up @@ -310,7 +310,7 @@ def vector(self) -> cx.SphericalPosition:
"""Return a vector."""
return cx.SphericalPosition(
r=Quantity([1, 2, 3, 4], "kpc"),
theta=Quantity([0, 36, 142, 180], "deg"),
theta=Quantity([1, 36, 142, 180 - 1e-4], "deg"),
phi=Quantity([0, 65, 135, 270], "deg"),
)

Expand All @@ -330,7 +330,9 @@ def test_spherical_to_cartesian1d(self, vector):
assert isinstance(cart1d, cx.CartesianPosition1D)
assert qnp.allclose(
cart1d.x,
Quantity([0, 0.49681753, -1.3060151, -4.1700245e-15], "kpc"),
Quantity(
[1.7452406e-02, 4.9681753e-01, -1.3060151e00, 8.6809595e-14], "kpc"
),
atol=Quantity(1e-8, "kpc"),
)

Expand All @@ -352,10 +354,13 @@ def test_spherical_to_cartesian2d(self, vector):
assert isinstance(cart2d, cx.CartesianPosition2D)
assert qnp.array_equal(
cart2d.x,
Quantity([0, 0.49681753, -1.3060151, -4.1700245e-15], "kpc"),
Quantity(
[1.7452406e-02, 4.9681753e-01, -1.3060151e00, 8.6809595e-14], "kpc"
),
)
assert qnp.array_equal(
cart2d.y, Quantity([0.0, 1.0654287, 1.3060151, 3.4969111e-07], "kpc")
cart2d.y,
Quantity([0.0000000e00, 1.0654287e00, 1.3060151e00, -7.2797034e-06], "kpc"),
)

@pytest.mark.filterwarnings("ignore:Irreversible dimension change")
Expand All @@ -366,7 +371,7 @@ def test_spherical_to_polar(self, vector):
assert isinstance(polar, cx.PolarPosition)
assert qnp.array_equal(
polar.r,
Quantity([0.0, 1.1755705, 1.8469844, -3.4969111e-07], "kpc"),
Quantity([1.7452406e-02, 1.1755705e00, 1.8469844e00, 7.2797034e-06], "kpc"),
)
assert qnp.array_equal(polar.phi, Quantity([0.0, 65.0, 135.0, 270.0], "deg"))

Expand All @@ -376,13 +381,17 @@ def test_spherical_to_cartesian3d(self, vector):

assert isinstance(cart3d, cx.CartesianPosition3D)
assert qnp.array_equal(
cart3d.x, Quantity([0, 0.49681753, -1.3060151, -4.1700245e-15], "kpc")
cart3d.x,
Quantity(
[1.7452406e-02, 4.9681753e-01, -1.3060151e00, 8.6809595e-14], "kpc"
),
)
assert qnp.array_equal(
cart3d.y, Quantity([0.0, 1.0654287, 1.3060151, 3.4969111e-07], "kpc")
cart3d.y,
Quantity([0.0, 1.0654287e00, 1.3060151e00, -7.2797034e-06], "kpc"),
)
assert qnp.array_equal(
cart3d.z, Quantity([1.0, 1.618034, -2.3640323, -4.0], "kpc")
cart3d.z, Quantity([0.9998477, 1.618034, -2.3640323, -4.0], "kpc")
)

def test_spherical_to_cartesian3d_astropy(self, vector, apyvector):
Expand All @@ -403,11 +412,11 @@ def test_spherical_to_cylindrical(self, vector):
assert isinstance(cyl, cx.CylindricalPosition)
assert qnp.array_equal(
cyl.rho,
Quantity([0.0, 1.1755705, 1.8469844, 3.4969111e-07], "kpc"),
Quantity([1.7452406e-02, 1.1755705e00, 1.8469844e00, 7.2797034e-06], "kpc"),
)
assert qnp.array_equal(cyl.phi, Quantity([0.0, 65.0, 135.0, 270.0], "deg"))
assert qnp.array_equal(
cyl.z, Quantity([1.0, 1.618034, -2.3640323, -4.0], "kpc")
cyl.z, Quantity([0.9998477, 1.618034, -2.3640323, -4.0], "kpc")
)

def test_spherical_to_cylindrical_astropy(self, vector, apyvector):
Expand All @@ -418,8 +427,7 @@ def test_spherical_to_cylindrical_astropy(self, vector, apyvector):

apycyl = apyvector.represent_as(apyc.CylindricalRepresentation)
# There's a 'bug' in Astropy where rho can be negative.
with pytest.raises(AssertionError):
assert convert(cyl.rho[-1], APYQuantity) == apycyl.rho[-1]
assert convert(cyl.rho[-1], APYQuantity) == apycyl.rho[-1]
assert np.allclose(convert(cyl.rho, APYQuantity), np.abs(apycyl.rho))

assert np.allclose(convert(cyl.z, APYQuantity), apycyl.z)
Expand Down

0 comments on commit 3622eed

Please sign in to comment.