From 4213779a4a1108f5908a51dd96ed468057f2c1f2 Mon Sep 17 00:00:00 2001 From: Chiara Marmo Date: Wed, 7 Sep 2022 08:22:36 -1000 Subject: [PATCH] Remove try statement. Add test. --- numpy/ma/core.py | 5 +---- numpy/ma/tests/test_core.py | 4 ++++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/numpy/ma/core.py b/numpy/ma/core.py index 405937046d47..812c48cedbdd 100644 --- a/numpy/ma/core.py +++ b/numpy/ma/core.py @@ -2357,10 +2357,7 @@ def masked_invalid(a, copy=True): """ - try: - return masked_where(~(np.isfinite(getdata(a))), a, copy=copy) - except TypeError: - raise + return masked_where(~(np.isfinite(getdata(a))), a, copy=copy) ############################################################################### # Printing options # diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py index 3c233b9cd7c3..8304a2d244ac 100644 --- a/numpy/ma/tests/test_core.py +++ b/numpy/ma/tests/test_core.py @@ -5317,6 +5317,10 @@ def test_masked_array_no_copy(): a = np.ma.array([1, 2, 3, 4], mask=[1, 0, 0, 0]) _ = np.ma.masked_where(a == 3, a, copy=False) assert_array_equal(a.mask, [True, False, True, False]) + # check masked array with masked_invalid is updated in place + a = np.ma.array([np.inf, 1, 2, 3, 4]) + _ = np.ma.masked_invalid(a, copy=False) + assert_array_equal(a.mask, [True, False, False, False, False]) def test_append_masked_array(): a = np.ma.masked_equal([1,2,3], value=2)