Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MRG] BUG: Fix dtype bug for counts #1227

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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