Skip to content

report.add_figure bad tags error not specific enough #10164

Closed

Description

@jasmainak

Describe the bug

The report class complains about a bad tag but does not say what characters are bad. Furthermore, I think it should allow numeric characters. I get:

ValueError: The following tags contained invalid characters: 'Subject 2002'

Steps to reproduce

Just do:

import matplotlib.pyplot as plt
from mne.report import Report

rep = Report()
subject = '2002'
fig = plt.figure()
rep.add_figure(fig, title=f'Figure {i}', tags=(f'Subject {subject}',))

Expected results

Report is produced with tag "subject 2002"

Actual results

Numeric subjects are quite common and I'd imagine a common usecase would be to use numeric tags. I think they should work ... did work previously in rep.add_figs_to_section, so I'd consider this a regression.

Additional information

I'm on latest master branch

Activity

  1. jasmainak commented on Dec 29, 2021

    @jasmainak
    MemberAuthor

    Also the docstring talks about "collection of str". I thought "collection" was a matplotlib object? It actually crosslinks to matplotlib. Is that what we mean? Shouldn't it be tuple | list or something like that?

  2. jasmainak commented on Dec 29, 2021

    @jasmainak
    MemberAuthor

    Another issue is that the rep.add_figure closes the figure. I don't think this should happen as user may still like to interact with the matplotlib figure while having it in a report for easier digestion.

  3. agramfort commented on Dec 30, 2021

    @agramfort
    SponsorMember
  4. hoechenberger commented on Jan 3, 2022

    @hoechenberger
    Member

    Also the docstring talks about "collection of str". I thought "collection" was a matplotlib object? It actually crosslinks to matplotlib. Is that what we mean?

    We mean a Python collection / container type, i.e., list, set, tuple, array. In the dev docstring, this has already been changed to array-like: https://mne.tools/dev/generated/mne.Report.html

    However we should adjust the error message as well.

    We don't allow for certain characters in tags, including spaces.

    _fig_to_img() has an auto_close parameter (defaults to True). We could expose this via the add_figure() API. WDYT?

  5. jasmainak commented on Jan 3, 2022

    @jasmainak
    MemberAuthor

    no strong feelings about exposing auto_close. I think if MNE-report creates a figure, it should auto-close, but if user created the figure (as in add_figure), it should not close, by default.

  6. hoechenberger commented on Jan 3, 2022

    @hoechenberger
    Member

    @jasmainak I think this makes sense, yes!

  7. changed the title [-]report.add_figure complains about bad tags[/-] [+]report.add_figure bad tags error not specific enough[/+] on Jan 4, 2022
  8. self-assigned this
    on Jan 6, 2022
  9. added a commit that references this issue on Jan 6, 2022
    a428065
  10. added 2 commits that reference this issue on Jan 21, 2022
    85e1bd4
    fe3e68c
  11. added a commit that references this issue on Jan 22, 2022
    ebaaed4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions