From 6a34c3879fca618daf3e6785882c8f0a52ee58ab Mon Sep 17 00:00:00 2001 From: Nicholas Earl Date: Fri, 13 Sep 2019 13:42:17 -0400 Subject: [PATCH 1/2] Stricter spectrum1d initialializer --- specutils/spectra/spectrum1d.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/specutils/spectra/spectrum1d.py b/specutils/spectra/spectrum1d.py index b45280168..325d44746 100644 --- a/specutils/spectra/spectrum1d.py +++ b/specutils/spectra/spectrum1d.py @@ -41,7 +41,15 @@ class Spectrum1D(OneDSpectrumMixin, NDDataRef): around with the spectrum container object. """ def __init__(self, flux=None, spectral_axis=None, wcs=None, - velocity_convention=None, rest_value=None, *args, **kwargs): + velocity_convention=None, rest_value=None, **kwargs): + # Check for pre-defined entries in the kwargs dictionary. + unknown_kwargs = set(kwargs).difference( + {'data', 'unit', 'uncertainty', 'meta', 'mask', 'copy'}) + + if len(unknown_kwargs) > 0: + raise ValueError("Initializer contains unknown arguments(s): {}." + "".format(', '.join(map(str, unknown_kwargs)))) + # If the flux (data) argument is a subclass of nddataref (as it would # be for internal arithmetic operations), avoid setup entirely. if isinstance(flux, NDDataRef): From df15e0ffd3da733a055196c24426a6ad62f3c005 Mon Sep 17 00:00:00 2001 From: Nicholas Earl Date: Fri, 13 Sep 2019 13:47:55 -0400 Subject: [PATCH 2/2] Include test for unkown keyword arguments --- specutils/tests/test_spectrum1d.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/specutils/tests/test_spectrum1d.py b/specutils/tests/test_spectrum1d.py index 41eb107ac..2deacb6d8 100644 --- a/specutils/tests/test_spectrum1d.py +++ b/specutils/tests/test_spectrum1d.py @@ -30,6 +30,11 @@ def test_create_from_arrays(): assert isinstance(spec.flux, u.Quantity) assert spec.flux.size == 50 + # Test creating spectrum with unknown arguments + with pytest.raises(ValueError) as e_info: + spec = Spectrum1D(wavelength=np.arange(1, 50) * u.nm, + flux=np.random.randn(48) * u.Jy) + def test_create_from_multidimensional_arrays(): """