Skip to content

FIX load_concat_dataset ignoring target_name and turning description strings into numbers - #1480

Merged
bruAristimunha merged 4 commits into
masterfrom
fix/load-concat-dataset
Oct 24, 2026
Merged

bruAristimunha merged 4 commits into
masterfrom
fix/load-concat-dataset

Conversation

@adammounir

Copy link
Copy Markdown
Collaborator

Two problems with load_concat_dataset on datasets saved with the current BaseConcatDataset.save format (braindecode/datautil/serialization.py).

1. target_name is silently ignored

The docstring says target_name loads that description column as the target. It is only passed to the outdated-format loader. For the current format, _load_parallel always takes the saved target_name.json, so the argument does nothing.

Repro: a RawDataset with description {"age": 30, "sex": "F"} and target_name="age", saved, then load_concat_dataset(path, preload=False, target_name="sex") gives target_name == "age" and y == 30.

Fix: for datasets of raws, set target_name on every loaded dataset (through RawDataset._target_name, so a missing key warns as in the constructor). For windowed datasets the targets live in the window metadata, so raise a ValueError that points to BaseConcatDataset.set_target, as the outdated loader already refused it (assert).

2. Numeric-looking description strings come back as numbers

description.json is read with pd.read_json(typ="series"), which infers dtypes. When all values of a description look numeric, they are converted: {"subject": "01", "session": "02", "run": "0"} comes back as {"subject": 1, "session": 2, "run": 0}. This happens for windowed datasets of BIDS-style data, whose description often only holds such entities. With a mixed description the strings are kept, so the result depends on the other fields.

Fix: read with dtype=False, so JSON strings stay strings and numbers stay numbers. JSON null (saved NaN) is still read back as NaN, as before.

Tests

3 new tests in test_serialization.py (description strings kept, target_name applied on raws, target_name on windows raises). All 3 fail on master. test_serialization.py: 37 passed. test_tuh.py, test_preprocess.py, test_mne_preprocessor.py: 238 passed, 14 skipped.

Full test files

Run on a Linux CPU node, on this branch rebased on current master and on master itself, with -m "not network and not huggingface": test/unit_tests/datautil/ test/unit_tests/datasets/test_dataset.py test/unit_tests/preprocessing/test_preprocess.py.
Branch: 270 passed, 1 skipped. master: 267 passed, 1 skipped. No test fails only on this branch.

@codecov

codecov Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.07%. Comparing base (489275e) to head (0aad99c).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1480      +/-   ##
==========================================
+ Coverage   91.04%   91.07%   +0.02%     
==========================================
  Files         167      167              
  Lines       21646    21663      +17     
==========================================
+ Hits        19708    19729      +21     
+ Misses       1938     1934       -4     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bruAristimunha bruAristimunha left a comment

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.

Super approved this one!

@bruAristimunha
bruAristimunha merged commit f44ba03 into master Oct 24, 2026
10 checks passed
@bruAristimunha
bruAristimunha deleted the fix/load-concat-dataset branch November 22, 2026 23:02
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.

2 participants