Skip to content

Commit

Permalink
Backport PR astropy#15844: BUG: fix a spurious warning when calling s…
Browse files Browse the repository at this point in the history
…igma_clipped_stats on a MaskedColumn
  • Loading branch information
neutrinoceros authored and meeseeksmachine committed Jan 16, 2024
1 parent 77d8489 commit b91ea30
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion astropy/stats/sigma_clipping.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ def _sigmaclip_noaxis(self, data, masked=True, return_bounds=False, copy=True):

# remove masked values and convert to ndarray
if isinstance(filtered_data, np.ma.MaskedArray):
filtered_data = filtered_data.data[~filtered_data.mask]
filtered_data = filtered_data._data[~filtered_data.mask]

# remove invalid values
good_mask = np.isfinite(filtered_data)
Expand Down
10 changes: 10 additions & 0 deletions astropy/stats/tests/test_sigma_clipping.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from astropy import units as u
from astropy.stats import mad_std
from astropy.stats.sigma_clipping import SigmaClip, sigma_clip, sigma_clipped_stats
from astropy.table import MaskedColumn
from astropy.utils.compat.optional_deps import HAS_SCIPY
from astropy.utils.exceptions import AstropyUserWarning
from astropy.utils.misc import NumpyRNGContext
Expand Down Expand Up @@ -163,6 +164,15 @@ def test_sigma_clipped_stats_ddof():
assert_allclose(stddev2, 0.98161731654802831)


def test_sigma_clipped_stats_masked_col():
# see https://github.com/astropy/astropy/issues/13281
arr = np.ma.masked_array([1, 2, 3], mask=[False, True, False])
sigma_clipped_stats(arr)

col = MaskedColumn(data=arr)
sigma_clipped_stats(col)


def test_invalid_sigma_clip():
"""Test sigma_clip of data containing invalid values."""

Expand Down
1 change: 1 addition & 0 deletions docs/changes/stats/15844.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a spurious warning when calling ``sigma_clipped_stats`` on a ``MaskedColumn``.

0 comments on commit b91ea30

Please sign in to comment.