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

BUG: Raise ImportError if optional dependency speclite is not installed #437

Merged
merged 2 commits into from
Feb 25, 2021
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
5 changes: 3 additions & 2 deletions skypy/utils/photometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
]

try:
import speclite.filters
import speclite.filters # noqa F401
except ImportError:
HAS_SPECLITE = False
else:
Expand Down Expand Up @@ -84,11 +84,12 @@ def mag_ab(wavelength, spectrum, filters, *, redshift=None, coefficients=None,
.. [1] M. R. Blanton et al., 2003, AJ, 125, 2348

'''
from speclite.filters import load_filters

# load the filters
if np.ndim(filters) == 0:
filters = (filters,)
filters = speclite.filters.load_filters(*filters)
filters = load_filters(*filters)
if np.shape(filters) == (1,):
filters = filters[0]

Expand Down
14 changes: 14 additions & 0 deletions skypy/utils/tests/test_photometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,17 @@ def __init__(self):
Planck15, resolution=2)
np.testing.assert_allclose(m_true, m_interp, rtol=1e-5)
assert not np.all(m_true == m_interp)


@pytest.mark.skipif(HAS_SPECLITE, reason='test requires that speclite is not installed')
def test_speclite_not_installed():
"""
Regression test for #436
Test that mag_ab raises the correct exception if speclite is not insalled.
"""
from skypy.utils.photometry import mag_ab
wavelength = np.linspace(1, 10, 100)
spectrum = np.ones(10)
filter = 'bessell-B'
with pytest.raises(ImportError):
mag_ab(wavelength, spectrum, filter)