Skip to content

Commit 489423b

Browse files
Backport PR #13341 on branch maint/1.10 (BUG: Fix bug with reading old reports) (#13344)
Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
1 parent 1d318a4 commit 489423b

3 files changed

Lines changed: 19 additions & 4 deletions

File tree

doc/changes/devel/13341.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix bug with :func:`mne.open_report` not working with old saved files, by `Eric Larson`_.

mne/report/report.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -714,12 +714,11 @@ def open_report(fname, **params):
714714
# Check **params with the loaded report
715715
read_hdf5, _ = _import_h5io_funcs()
716716
state = read_hdf5(fname, title="mnepython")
717+
for param, default in _backward_compat_map.items():
718+
state.setdefault(param, default)
717719
for param in params:
718720
if param not in state:
719-
if param in _backward_compat_map:
720-
state[param] = _backward_compat_map[param]
721-
else:
722-
raise ValueError(f"The loaded report has no attribute {param}")
721+
raise ValueError(f"The loaded report has no attribute {param}")
723722
if params[param] != state[param]:
724723
raise ValueError(
725724
f"Attribute '{param}' of loaded report ({params[param]}) does not "

mne/report/tests/test_report.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,6 +1172,21 @@ def test_report_tweaks(tmp_path, monkeypatch):
11721172
assert img.shape == (2000, 2000, 3) # figure.figsize * figure.dpi
11731173

11741174

1175+
def test_report_backward_compat(tmp_path):
1176+
"""Ensure our options are still backward compatible."""
1177+
h5io = pytest.importorskip("h5io")
1178+
fname = tmp_path / "report.h5"
1179+
r = Report()
1180+
r.img_max_width = 600
1181+
r.save(fname)
1182+
h = h5io.read_hdf5(fname, title="mnepython")
1183+
assert h["img_max_width"] == 600
1184+
del h["img_max_width"]
1185+
h5io.write_hdf5(fname, h, title="mnepython", overwrite=True)
1186+
with open_report(fname) as r2:
1187+
assert r2.img_max_width == 850
1188+
1189+
11751190
@pytest.mark.slowtest # 30 s on Azure
11761191
@testing.requires_testing_data
11771192
def test_manual_report_3d(tmp_path, renderer):

0 commit comments

Comments
 (0)