Skip to content

Commit

Permalink
Fix some comparisons that should have been using isinstance (#1071)
Browse files Browse the repository at this point in the history
  • Loading branch information
rosteen authored Jul 31, 2023
1 parent bea93e7 commit e799aa6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions specutils/spectra/spectrum1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,9 @@ def __getitem__(self, item):
handled here.
"""

if self.flux.ndim > 1 or (type(item) == tuple and item[0] == Ellipsis):
if type(item) == tuple:
if len(item) == len(self.flux.shape) or item[0] == Ellipsis:
if self.flux.ndim > 1 or (isinstance(item, tuple) and item[0] is Ellipsis):
if isinstance(item, tuple):
if len(item) == len(self.flux.shape) or item[0] is Ellipsis:
spec_item = item[-1]
if not isinstance(spec_item, slice):
if isinstance(item, u.Quantity):
Expand Down
12 changes: 6 additions & 6 deletions specutils/tests/test_spectral_axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def test_change_redshift():

assert spec.redshift.unit.physical_type == 'dimensionless'
assert_quantity_allclose(spec.redshift, u.Quantity(0))
assert type(spec.spectral_axis) == SpectralAxis
assert isinstance(spec.spectral_axis, SpectralAxis)

with pytest.warns(
AstropyDeprecationWarning,
Expand All @@ -182,13 +182,13 @@ def test_change_redshift():

assert spec.redshift.unit.physical_type == 'dimensionless'
assert_quantity_allclose(spec.redshift, u.Quantity(0.1))
assert type(spec.spectral_axis) == SpectralAxis
assert isinstance(spec.spectral_axis, SpectralAxis)

spec = Spectrum1D(spectral_axis=wave, flux=flux, redshift=0.2)

assert spec.redshift.unit.physical_type == 'dimensionless'
assert_quantity_allclose(spec.redshift, u.Quantity(0.2))
assert type(spec.spectral_axis) == SpectralAxis
assert isinstance(spec.spectral_axis, SpectralAxis)

with pytest.warns(
AstropyDeprecationWarning,
Expand All @@ -198,7 +198,7 @@ def test_change_redshift():

assert spec.redshift.unit.physical_type == 'dimensionless'
assert_quantity_allclose(spec.redshift, u.Quantity(0.4))
assert type(spec.spectral_axis) == SpectralAxis
assert isinstance(spec.spectral_axis, SpectralAxis)


def test_no_change_redshift():
Expand All @@ -208,13 +208,13 @@ def test_no_change_redshift():

assert spec.redshift.unit.physical_type == 'dimensionless'
assert_quantity_allclose(spec.redshift, u.Quantity(0))
assert type(spec.spectral_axis) == SpectralAxis
assert isinstance(spec.spectral_axis, SpectralAxis)

spec.set_redshift_to(0.5)

assert spec.redshift.unit.physical_type == 'dimensionless'
assert_quantity_allclose(spec.redshift, u.Quantity(0.5))
assert type(spec.spectral_axis) == SpectralAxis
assert isinstance(spec.spectral_axis, SpectralAxis)

assert_quantity_allclose(spec.wavelength, wave)

Expand Down

0 comments on commit e799aa6

Please sign in to comment.