Repository navigation
Add __repr__ and _repr_html_ to dataset classes for meaningful representation - #934
Conversation
Co-authored-by: bruAristimunha <[email protected]>
__repr__ and _repr_html_ to dataset classes for meaningful representation
|
@copilot, pre commit and what's new file please |
Co-authored-by: bruAristimunha <[email protected]>
There was a problem hiding this comment.
💡 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".
- 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.
|
@codex, review please |
There was a problem hiding this comment.
💡 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".
| 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()) |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
Fixed in 1192977. Added a len(sizes) == 0 guard in _metadata_summary so empty metadata no longer produces NaN from min()/max().
There was a problem hiding this comment.
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.rstto 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.
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
__repr__toRawDatasetshowing channel count, type, sfreq, duration, description__repr__toEEGWindowsDatasetshowing channel count, window size, sfreq, n_windows, description__repr__toWindowsDatasetshowing same info asEEGWindowsDataset__repr__toBaseConcatDatasetshowing n_recordings, total size, first-record signal details (sfreq, channels, ch_names, montage, duration/window), description summary_repr_html_toBaseConcatDatasetfor Jupyter notebook HTML rendering*annotationCounterimport to module level (no inline imports)str(c)conversiondocs/whats_new.rstOriginal prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.