diff --git a/doc/whats_new.rst b/doc/whats_new.rst index 6aa4a8830..d87fb95ca 100644 --- a/doc/whats_new.rst +++ b/doc/whats_new.rst @@ -51,7 +51,8 @@ Detailed list of changes 🪲 Bug fixes ^^^^^^^^^^^^ -- nothing yet +- The datatype in the dataframe returned by :func:`mne_bids.stats.count_events` is now + ``pandas.Int64Dtype`` instead of ``float64``. ⚕️ Code health ^^^^^^^^^^^^^^ diff --git a/mne_bids/stats.py b/mne_bids/stats.py index 01906c578..3e6c2bcca 100644 --- a/mne_bids/stats.py +++ b/mne_bids/stats.py @@ -32,6 +32,12 @@ def count_events(root_or_path, datatype="auto"): counts : pandas.DataFrame The pandas dataframe containing all the counts of trial_type in all matching events.tsv files. + + Notes + ----- + .. versionchanged:: 0.15 + Table values were changed from floats (with NaN for missing values) + to Pandas nullable integer arrays. """ import pandas as pd @@ -105,7 +111,8 @@ def count_events(root_or_path, datatype="auto"): groups.append("trial_type") counts = df.groupby(groups).size() - counts = counts.unstack() + counts = counts.unstack(fill_value=-1) + counts.replace(-1, pd.NA, inplace=True) if "BAD_ACQ_SKIP" in counts.columns: counts = counts.drop("BAD_ACQ_SKIP", axis=1)