Skip to content

Commit 82247f9

Browse files
authored
Add warning about spectral_axis_index being ignored in 1.x (#1238)
* Add warning about spectral_axis_index being ignored in 1.x * Slight change * Fix failing test * Ignore UnitBase warning in readthedocs * Update changelog
1 parent 3e6ea5e commit 82247f9

File tree

3 files changed

+15
-17
lines changed

3 files changed

+15
-17
lines changed

CHANGES.rst

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
1.21.0 (unreleased)
2-
-------------------
3-
4-
New Features
5-
^^^^^^^^^^^^
6-
7-
Bug Fixes
8-
^^^^^^^^^
9-
10-
Other Changes and Additions
11-
^^^^^^^^^^^^^^^^^^^^^^^^^^^
12-
131
1.20.2 (unreleased)
142
-------------------
153

@@ -22,6 +10,8 @@ Bug Fixes
2210
Other Changes and Additions
2311
^^^^^^^^^^^^^^^^^^^^^^^^^^^
2412

13+
- Warn about use of ``spectral_axis_index`` (new Spectrum1D kwarg for 2.0) in 1.x. [#1238]
14+
2515
1.20.1 (2025-05-07)
2616
-------------------
2717

docs/nitpick-exceptions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ py:obj NDUncertainty
77

88
# Links that might not work yet, depending on the astropy version
99
py:obj astropy.coordinates.SpectralQuantity
10+
py:class astropy.units.UnitBase
1011

1112
# Classes in the SpectralCoord/SpectralQuantity methods for which we can't
1213
# control the API links.

specutils/spectra/spectrum1d.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,22 @@ def __init__(self, flux=None, spectral_axis=None, wcs=None,
7474
radial_velocity=None, bin_specification=None, **kwargs):
7575

7676
# These will be new keywords in 2.x, we pop them here in case the
77-
# alias for the new class name is being used
78-
if 'move_spectral_axis' in kwargs:
77+
# alias for the new class name is being used, and warn in cases that
78+
# would result in different behavior between 1.x and 2.x
79+
if 'move_spectral_axis' in kwargs or 'spectral_axis_index' in kwargs:
7980
good_inds = ['last', -1, None]
80-
if flux is not None:
81+
if flux is not None and hasattr(flux, 'ndim'):
8182
good_inds.append(flux.ndim - 1)
83+
84+
if 'move_spectral_axis' in kwargs:
8285
move_spectral_axis = kwargs.pop('move_spectral_axis', None)
8386
if move_spectral_axis not in good_inds:
84-
warnings.warn("move_spectral_axis is ignored in specutils 1.x.")
85-
kwargs.pop('spectral_axis_index', None)
87+
warnings.warn('move_spectral_axis is ignored in specutils 1.x.')
88+
89+
if 'spectral_axis_index' in kwargs:
90+
spectral_axis_index = kwargs.pop('spectral_axis_index', None)
91+
if spectral_axis_index not in good_inds:
92+
warnings.warn('spectral_axis_index is ignored in specutils 1.x.')
8693

8794
# Check for pre-defined entries in the kwargs dictionary.
8895
unknown_kwargs = set(kwargs).difference(

0 commit comments

Comments
 (0)