Repository navigation
FIX: Save numpy scalar and array kwargs as JSON in BaseConcatDataset.save - #1863
Merged
bruAristimunha merged 4 commits intoDec 1, 2026
Merged
bruAristimunha merged 4 commits into
bruAristimunha merged 4 commits into
Conversation
The helper was inserted between the decorator and the class, so it registered _json_default itself and BaseConcatDataset disappeared from the dataset registry (get_dataset_class KeyError, CI shards 1-2 red). Move the decorator back onto the class.
Collaborator
|
Maintainer note: moved |
3 tasks done
bruAristimunha
added a commit
to AxelNoun/braindecode
that referenced
this pull request
Dec 1, 2026
…rrays Review follow-up (P2/P3): exact-type checks left subclasses of list/tuple/dict (OrderedDict, custom lists) holding raw NumPy scalars (JSON then fails or silently drops them), never converted NumPy dict keys, and dropped 0-d arrays. Widen to isinstance, normalize keys, and unwrap 0-d arrays with .item() like the dataset save path (braindecode#1863).
bruAristimunha
added a commit
that referenced
this pull request
Dec 1, 2026
* FIX get_config: keep NumPy scalar arguments as Python numbers build_model_config and the Hugging Face Hub config left out arguments passed as NumPy scalars (np.int64, np.float32), so from_config and from_pretrained rebuilt the default. Convert NumPy scalars, also inside lists, tuples and dicts, to Python numbers before the JSON checks, and in _update_init_kwargs so reset_head(np.int64(n)) keeps the config serializable. * Add the PR number to the changelog entry * FIX get_config: traverse container subclasses, NumPy dict keys, 0-d arrays Review follow-up (P2/P3): exact-type checks left subclasses of list/tuple/dict (OrderedDict, custom lists) holding raw NumPy scalars (JSON then fails or silently drops them), never converted NumPy dict keys, and dropped 0-d arrays. Widen to isinstance, normalize keys, and unwrap 0-d arrays with .item() like the dataset save path (#1863). --------- Co-authored-by: bruAristimunha <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was broken.
preprocess(..., save_dir=...)andBaseConcatDataset.save()raisedTypeError: Object of type int64 is not JSON serializablewhen a preprocessor or windower kwarg was a numpy scalar or array (for examplenp.int64window sizes). The error came after the fif files were written, so the save directory stayed partial and a rerun failed withFileExistsError.What changed. A small
_json_defaulthelper converts numpy scalars and arrays with.tolist(). It is passed to the twojson.dump(kwargs, ...)calls inbraindecode/datasets/base.py. Other types still raiseTypeError. Adds awhats_newentry (the:gh:number is set after the PR opens).How tested.
pytest test/unit_tests/datautil/test_serialization.py -n 2: 43 passed, 1 skipped.base.pychange reverted, the 4 new tests fail withTypeError: Object of type ndarray/int64 is not JSON serializable.AI disclosure: this PR was prepared with AI assistance (Claude, Anthropic).