Skip to content

Commit b8b2e47

Browse files
committed
Adding test
1 parent 5a88e36 commit b8b2e47

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

mne/utils/check.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,7 @@ def _path_like(item):
701701

702702
def _check_if_nan(data, on_nan="error", msg=" to be plotted"):
703703
"""Raise if any of the values are NaN."""
704+
_check_option("on_nan", on_nan, ("error", "warn"))
704705
if not np.isfinite(data).all():
705706
if on_nan == "error":
706707
raise ValueError(f"Some of the values {msg} are NaN.")

mne/utils/tests/test_check.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
_check_ch_locs,
2222
_check_fname,
2323
_check_info_inv,
24+
_check_if_nan,
2425
_check_option,
2526
_check_range,
2627
_check_sphere,
@@ -206,6 +207,24 @@ def test_check_option():
206207
assert _check_option("option", "bad", ["valid"])
207208

208209

210+
def test_check_if_nan():
211+
"""Test NaN handling and option validation."""
212+
msg = (
213+
"Invalid value for the 'on_nan' parameter. "
214+
"Allowed values are 'error' and 'warn', but got 'er' instead."
215+
)
216+
nan_error_msg = r"Some of the values\s+to be plotted are NaN\."
217+
nan_warn_msg = r"Some of the values\s+to be plotted are NaN"
218+
with pytest.raises(ValueError, match=msg):
219+
_check_if_nan([0.0], on_nan="er")
220+
221+
with pytest.raises(ValueError, match=nan_error_msg):
222+
_check_if_nan([0.0, np.nan], on_nan="error")
223+
224+
with pytest.warns(RuntimeWarning, match=nan_warn_msg):
225+
_check_if_nan([0.0, np.nan], on_nan="warn")
226+
227+
209228
def test_path_like():
210229
"""Test _path_like()."""
211230
str_path = str(base_dir)

0 commit comments

Comments
 (0)