Skip to content

Add __repr__ and _repr_html_ to dataset classes for meaningful representation - #934

Merged
bruAristimunha merged 7 commits into
masterfrom
copilot/improve-dataset-representation
Feb 21, 2026
Merged

bruAristimunha merged 7 commits into
masterfrom
copilot/improve-dataset-representation

Conversation

Copilot AI commented Feb 20, 2026 •

Copy link
Copy Markdown
Contributor
  • Add __repr__ to RawDataset showing channel count, type, sfreq, duration, description
  • Add __repr__ to EEGWindowsDataset showing channel count, window size, sfreq, n_windows, description
  • Add __repr__ to WindowsDataset showing same info as EEGWindowsDataset
  • Add __repr__ to BaseConcatDataset showing n_recordings, total size, first-record signal details (sfreq, channels, ch_names, montage, duration/window), description summary
  • Add _repr_html_ to BaseConcatDataset for Jupyter notebook HTML rendering
  • Mark first-record-based info with * annotation
  • Move Counter import to module level (no inline imports)
  • Handle integer column names safely with str(c) conversion
  • Add 6 tests covering all new repr methods
  • Run pre-commit hooks (ruff-format applied, all hooks pass)
  • Add what's new entry in docs/whats_new.rst
  • All 51 tests pass, no CodeQL alerts
Original prompt

This section details on the original issue you should resolve

<issue_title>The representation of the dataset is not clear within str and html representation</issue_title>
<issue_description>At the moment, when you print the dataset, we are only able to see the object classes name.

This needs to be improved, so all it is clear all the details of the dataset.

I would like some nice rich representation that summarizes everything that we have within the metadata, and also the size of the object at the moment.

The rich dep should be optional, and to construct the details about number of channels, time dimension, we should only consume the first instance. And for the information within the raw, we should only consume the info details for the first dataset within the list.
Some nice visualizations in plain text should be made for the channel, and if the montage is available, some small text represents using some text representation.

Some type of *indicating that come from the first record.

It is okay to have multiple lines, but I don't want such essay text.

Within the PR, I want option of previous to me decide the one that I want.

Use fake dataset to show this.</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Enhance dataset representation in string and HTML formats Add __repr__ and _repr_html_ to dataset classes for meaningful representation Feb 20, 2026
Copilot AI requested a review from bruAristimunha February 20, 2026 10:11
@bruAristimunha

Copy link
Copy Markdown
Collaborator

@copilot, pre commit and what's new file please

Copilot AI commented Feb 20, 2026

Copy link
Copy Markdown
Contributor Author

@copilot, pre commit and what's new file please

Done in d793cdb:

  • Applied ruff-format fixes (all pre-commit hooks now pass on the changed files)
  • Added a what's new entry under the Enhancements section of docs/whats_new.rst

@bruAristimunha
bruAristimunha marked this pull request as ready for review February 20, 2026 21:16

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d793cdb1bd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread braindecode/datasets/base.py Resolved
Comment thread braindecode/datasets/base.py Resolved
- Add _repr_html_ to RawDataset, EEGWindowsDataset, and WindowsDataset
- Show target distribution and extra metadata columns in windowed dataset reprs
- Derive window duration from get_metadata() in BaseConcatDataset (no longer
  first-recording-only)
- Extract _channel_info(), _window_info(), _html_row(), _metadata_summary()
  helpers to eliminate duplicated signal-gathering logic
- Simplify _signal_summary() to return (mne_obj, is_windowed) tuple
- Handle _LazyDataFrame gracefully (degrade to "lazy (N windows)")
- Add 7 new tests for repr_html and metadata display
When datasets have zero windows, crop_inds is empty and indexing
crop_inds[0] raises IndexError. Return None from _window_info for
empty arrays and handle it gracefully in all repr methods.
@bruAristimunha

Copy link
Copy Markdown
Collaborator

@codex, review please

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fcc48efb62

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread braindecode/datasets/base.py Outdated
window_info = None
if "i_start_in_trial" in metadata.columns and "i_stop_in_trial" in metadata.columns:
sizes = metadata["i_stop_in_trial"] - metadata["i_start_in_trial"]
min_s, max_s = int(sizes.min()), int(sizes.max())

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Handle empty metadata before computing window min/max

Guard this min/max conversion for empty metadata, because sizes.min()/sizes.max() are NaN when a windowed dataset has zero rows and int(NaN) raises ValueError. That makes __repr__ and _repr_html_ fail for EEGWindowsDataset, WindowsDataset, and BaseConcatDataset whenever preprocessing/splitting produces an empty window set, which breaks notebook rendering and simple logging of those datasets.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 1192977. Added a len(sizes) == 0 guard in _metadata_summary so empty metadata no longer produces NaN from min()/max().

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds informative __repr__ and _repr_html_ methods to dataset classes (RawDataset, EEGWindowsDataset, WindowsDataset, and BaseConcatDataset) to provide meaningful representations when printing datasets or displaying them in Jupyter notebooks. The representations include channel count/types, sampling frequency, duration/window information, channel names, montage details, description summaries, and metadata information including target distributions.

Changes:

  • Added helper functions (_html_row, _metadata_summary, _channel_info, _window_info) to support repr generation
  • Implemented __repr__ and _repr_html_ for all dataset classes with comprehensive information display
  • Added extensive test coverage for all new repr methods across different dataset types
  • Updated documentation in docs/whats_new.rst to describe the new functionality

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.

File Description
braindecode/datasets/base.py Core implementation: added 4 helper functions and __repr__/_repr_html_ methods to RawDataset, EEGWindowsDataset, WindowsDataset, and BaseConcatDataset classes
test/unit_tests/datasets/test_dataset.py Comprehensive test coverage: 11 new tests covering repr functionality for all dataset types including metadata handling
docs/whats_new.rst Documentation of the new feature in the changelog with detailed description of what information is displayed

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread braindecode/datasets/base.py Resolved
Comment thread braindecode/datasets/base.py Resolved
Comment thread braindecode/datasets/base.py Resolved
Comment thread braindecode/datasets/base.py Resolved
Comment thread braindecode/datasets/base.py Resolved
Comment thread braindecode/datasets/base.py Resolved
Comment thread braindecode/datasets/base.py Resolved
Introduce a lightweight _ReprBuilder class that accumulates structured
data and renders both __repr__ and _repr_html_ from the same source,
removing duplicated data gathering across all dataset classes. Extract
shared windowed-dataset logic into _build_windowed_repr. Subclasses
now only override _build_repr() while inheriting render methods from
RecordDataset. Net reduction of ~120 lines.
…ation

- Escape HTML special characters in _html_row and _ReprBuilder.to_html
  to prevent XSS in notebook environments
- Guard _metadata_summary against empty metadata where min/max would
  produce NaN and raise ValueError
- Add empty datasets guard in BaseConcatDataset._build_repr to handle
  edge case of zero datasets
- Replace get_metadata() (full DataFrame concatenation) with lightweight
  _concat_metadata_summary that iterates per-dataset without allocating
  a combined DataFrame, improving repr performance for large datasets
@bruAristimunha
bruAristimunha merged commit aea10e5 into master Feb 21, 2026
10 checks passed
@bruAristimunha
bruAristimunha deleted the copilot/improve-dataset-representation branch February 21, 2026 00:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The representation of the dataset is not clear within __str__ and html representation

3 participants