@@ -226,3 +226,25 @@ def test_psd_array_welch_n_jobs():
226226 data = np .zeros ((1 , 2048 ))
227227 psd_array_welch (data , 1024 , n_jobs = 1 )
228228 psd_array_welch (data , 1024 , n_jobs = 2 )
229+
230+
231+ def test_psd_raises_on_inf_in_analyzed_window_array ():
232+ """psd_array_welch should fail if +Inf lies inside analyzed samples."""
233+ n_samples , n_fft , n_overlap = 2048 , 256 , 128
234+ rng = np .random .RandomState (0 )
235+ x = rng .randn (1 , n_samples )
236+ # Put +Inf inside the series; this falls within Welch windows
237+ x [0 , 800 ] = np .inf
238+ with pytest .raises (ValueError , match = "non[- ]?finite|NaN|Inf" ):
239+ psd_array_welch (x , float (n_fft ), n_fft = n_fft , n_overlap = n_overlap )
240+
241+
242+ def test_psd_raises_on_misaligned_nan_across_channels ():
243+ """If NaNs are present but masks are NOT aligned across channels, raise."""
244+ n_samples , n_fft , n_overlap = 2048 , 256 , 128
245+ rng = np .random .RandomState (42 )
246+ x = rng .randn (2 , n_samples )
247+ # NaN only in ch0; ch1 has no NaN => masks not aligned -> should raise
248+ x [0 , 500 ] = np .nan
249+ with pytest .raises (ValueError , match = "aligned|not aligned|non[- ]?finite|NaN|Inf" ):
250+ psd_array_welch (x , float (n_fft ), n_fft = n_fft , n_overlap = n_overlap )
0 commit comments