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: Do not use getdata() in np.ma.masked_invalid #22839

Merged
merged 1 commit into from Dec 20, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions numpy/ma/core.py
Expand Up @@ -2356,8 +2356,8 @@ def masked_invalid(a, copy=True):
fill_value=1e+20)

"""

return masked_where(~(np.isfinite(getdata(a))), a, copy=copy)
a = np.array(a, copy=False, subok=True)
return masked_where(~(np.isfinite(a)), a, copy=copy)

###############################################################################
# Printing options #
Expand Down
14 changes: 14 additions & 0 deletions numpy/ma/tests/test_core.py
Expand Up @@ -4505,6 +4505,20 @@ def test_masked_invalid_error(self):
match="not supported for the input types"):
np.ma.masked_invalid(a)

def test_masked_invalid_pandas(self):
# getdata() used to be bad for pandas series due to its _data
# attribute. This test is a regression test mainly and may be
# removed if getdata() is adjusted.
class Series():
_data = "nonsense"

def __array__(self):
return np.array([5, np.nan, np.inf])

arr = np.ma.masked_invalid(Series())
assert_array_equal(arr._data, np.array(Series()))
assert_array_equal(arr._mask, [False, True, True])

def test_choose(self):
# Test choose
choices = [[0, 1, 2, 3], [10, 11, 12, 13],
Expand Down