Skip to content

np.nan in mne.stats.permutation_t_test fails silently #13767

@skjerns

Description

@skjerns

I've recently encountered a situation where I had a np.nan in the data I was running a permutation_t_test on. This failed (expectedly), however, it did not give me any warning/error! I only realized because a pvalue=0 seemed a bit suspicious in my plot

I think that it should at least print a warning, similar to how it give a RuntimeWarning when one test's observations are all zero (probably due to underlying numpy warnings.)

I assume this is the same for other functions in the stats module. If this is something that should be improved, probably best to do it systematically for all functions?

import mne
import numpy as np

x = np.random.rand(20, 20)
x[:, 0] = np.nan
t_obs, pvals, h0 = mne.stats.permutation_t_test(x)
# Permuting 9999 times...
# no warning printed! But all h0 are np.nan

# when one test is 0 for all observations, there is a warning
x = np.random.rand(20, 20)
x[:, 0] = 0
t_obs, pvals, h0 =  mne.stats.permutation_t_test(x)
# Permuting 9999 times...
# /home/simon/anaconda3/envs/default/lib/python3.14/site-packages/mne/stats/permutations.py:20: RuntimeWarning: invalid value encountered in divide
#  max_abs = np.max(np.abs(mus) / (stds / sqrt(n_samples)), axis=1)  # t-max

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions