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

Some cleanups #934

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
64 changes: 1 addition & 63 deletions mne_bids_pipeline/_report.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import contextlib
import re
import traceback
from functools import lru_cache
from io import StringIO
Expand All @@ -13,6 +12,7 @@
import pandas as pd
from filelock import FileLock
from mne.io import BaseRaw
from mne.report.report import _df_bootstrap_table
from mne.utils import _pl
from mne_bids import BIDSPath
from mne_bids.stats import count_events
Expand Down Expand Up @@ -900,65 +900,3 @@ def _render_bem(
replace=True,
n_jobs=1, # prevent automatic parallelization
)


# Copied from mne/report/report.py

try:
from mne.report.report import _df_bootstrap_table
except ImportError: # MNE < 1.7

def _df_bootstrap_table(*, df, data_id):
html = df.to_html(
border=0,
index=False,
show_dimensions=True,
justify="unset",
float_format=lambda x: f"{x:.3f}",
classes="table table-hover table-striped table-sm table-responsive small",
na_rep="",
)
htmls = html.split("\n")
header_pattern = "<th>(.*)</th>"

for idx, html in enumerate(htmls):
if "<table" in html:
htmls[idx] = html.replace(
"<table",
"<table "
'id="mytable" '
'data-toggle="table" '
f'data-unique-id="{data_id}" '
'data-search="true" ' # search / filter
'data-search-highlight="true" '
'data-show-columns="true" ' # show/hide columns
'data-show-toggle="true" ' # allow card view
'data-show-columns-toggle-all="true" '
'data-click-to-select="true" '
'data-show-copy-rows="true" '
'data-show-export="true" ' # export to a file
'data-export-types="[csv]" '
'data-export-options=\'{"fileName": "metadata"}\' '
'data-icon-size="sm" '
'data-height="400"',
)
continue
elif "<tr" in html:
# Add checkbox for row selection
htmls[idx] = (
f"{html}\n" f'<th data-field="state" data-checkbox="true"></th>'
)
continue

col_headers = re.findall(pattern=header_pattern, string=html)
if col_headers:
# Make columns sortable
assert len(col_headers) == 1
col_header = col_headers[0]
htmls[idx] = html.replace(
"<th>",
f'<th data-field="{col_header.lower()}" ' f'data-sortable="true">',
)

html = "\n".join(htmls)
return html