Skip to content

Commit 81a79d6

Browse files
mhvkDerek Homeier
authored andcommitted
Test that equivalencies now properly work within ufuncs [closes astropy#2496]
1 parent 1d4532a commit 81a79d6

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

‎CHANGES.rst‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,9 @@ New Features
411411

412412
- ``astropy.units``
413413

414+
- Ensure equivalencies that do more than just scale a ``Quantity`` are
415+
properly handled also in ``ufunc`` evaluations. [#2496, #3586]
416+
414417
- ``astropy.utils``
415418

416419
- ``astropy.vo``

‎astropy/units/tests/test_equivalencies.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,14 @@ class MyQuantityLookalike(np.ndarray):
476476
assert all(eq in set(eq_on) for eq in eq_off)
477477
assert set(eq_off) < set(eq_on)
478478

479+
# Check the equivalency manager also works in ufunc evaluations,
480+
# not just using (wrong) scaling. [#2496]
481+
l2v = u.doppler_optical(6000 * u.angstrom)
482+
l1 = 6010 * u.angstrom
483+
assert l1.to(u.km/u.s, equivalencies=l2v) > 100. * u.km / u.s
484+
with u.set_enabled_equivalencies(l2v):
485+
assert l1 > 100. * u.km / u.s
486+
assert abs((l1 - 500. * u.km / u.s).to(u.angstrom)) < 1. * u.km/u.s
479487

480488
def test_equivalency_context_manager():
481489
base_registry = u.get_current_unit_registry()
@@ -519,7 +527,6 @@ def test_temperature():
519527

520528

521529
def test_temperature_energy():
522-
from ... import constants
523530
x = 1000 * u.K
524531
y = (x * constants.k_B).to(u.keV)
525532
assert_allclose(x.to(u.keV, u.temperature_energy()).value, y)

0 commit comments

Comments
 (0)