Skip to content

Commit

Permalink
[MRG] BUG: Fix dtype bug for counts (#1227)
Browse files Browse the repository at this point in the history
BUG: Fix dtype bug for counts
  • Loading branch information
larsoner authored Feb 16, 2024
1 parent b85a0dc commit 4fd0ba0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion doc/whats_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^^^^^^^^^
Expand Down
9 changes: 8 additions & 1 deletion mne_bids/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4fd0ba0

Please sign in to comment.