File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -701,6 +701,7 @@ def _path_like(item):
701701
702702def _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." )
Original file line number Diff line number Diff line change 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+
209228def test_path_like ():
210229 """Test _path_like()."""
211230 str_path = str (base_dir )
You can’t perform that action at this time.
0 commit comments