Skip to content

Commit

Permalink
[MRG] Turn off datatype check (#744)
Browse files Browse the repository at this point in the history
* Fixing datatype check.

* Fix pr number.

* Update changelog

* Fix unit test.

* Fixing docstring.

* Rework Notes section

* Example indentation

Co-authored-by: Richard Höchenberger <richard.hoechenberger@gmail.com>
  • Loading branch information
adam2392 and hoechenberger committed Mar 22, 2021
1 parent 2b17768 commit a2b0350
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
3 changes: 2 additions & 1 deletion doc/whats_new.rst
Expand Up @@ -43,10 +43,11 @@ Enhancements
- Improve the ``Convert iEEG data to BIDS`` tutorial to include a note on how BIDS and MNE-Python coordinate frames are handled, by `Adam Li`_ (:gh:`717`)
- More detailed error messages when trying to write modified data via :func:`mne_bids.write_raw_bids`, by `Richard Höchenberger`_ (:gh:`719`)
- If ``check=True``, :class:`mne_bids.BIDSPath` now checks the ``space`` entity to be valid according to BIDS specification Appendix VIII, by `Stefan Appelhoff`_ (:gh:`724`)
- ``BIDSPath.root`` now automatically expands ``~`` to the user's home directory, by `Richard Höchenberger`_ (:gh:`725`)
- Data types that are currently unsupported by MNE-BIDS (e.g. ``dwi``, ``func``) can now be used in :class:`mne_bids.BIDSPath` by setting ``check=False``, by `Adam Li`_ (:gh:`744`)
- Arbitrary file names can now be represented as a `BIDSPath`` by passing the entire name as ``suffix`` and setting ``check=False``, by `Adam Li`_ (:gh:`729`)
- Add support for MNE's flux excitation channel (``exci``), by `Maximilien Chaumon`_ (:gh:`728`)
- :meth:`mne_bids.BIDSPath.match` gained a new parameter ``check``; when setting ``check=True``, ``match()`` will only return paths that conform to BIDS, by `Richard Höchenberger`_ (:gh:`726`)
- ``BIDSPath.root`` now automatically expands ``~`` to the user's home directory, by `Richard Höchenberger`_ (:gh:`725`)

API and behavior changes
^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
22 changes: 14 additions & 8 deletions mne_bids/path.py
Expand Up @@ -228,15 +228,15 @@ class BIDSPath(object):
Examples
--------
>>> bids_path = BIDSPath(subject='test', session='two', task='mytask',
suffix='ieeg', extension='.edf')
suffix='ieeg', extension='.edf')
>>> print(bids_path.basename)
sub-test_ses-two_task-mytask_ieeg.edf
>>> bids_path
BIDSPath(root: None,
basename: sub-test_ses-two_task-mytask_ieeg.edf)
>>> # copy and update multiple entities at once
>>> new_bids_path = bids_path.copy().update(subject='test2',
session='one')
session='one')
>>> print(new_bids_path.basename)
sub-test2_ses-one_task-mytask_ieeg.edf
>>> # printing the BIDSPath will show relative path when
Expand All @@ -261,15 +261,20 @@ class BIDSPath(object):
Notes
-----
BIDS entities are separated generally with a ``"_"`` character, while
entity key/value pairs are separated with a ``"-"`` character (e.g.
``subject``, ``session``, ``task``, etc.). There are checks performed
to make sure that there are no ``'-'``, ``'_'``, or ``'/'`` characters
associated with any of these entities.
BIDS entities are generally separated with a ``"_"`` character, while
entity key/value pairs are separated with a ``"-"`` character.
There are checks performed to make sure that there are no ``'-'``, ``'_'``,
or ``'/'`` characters contained in any entity keys or values.
To represent a filename such as ``dataset_description.json``,
one can set ``check=False``, and pass ``suffix='dataset_description'``
and ``extension='.json'``.
``BIDSPath`` can also be used to represent file and folder names of data
types that are not yet supported through MNE-BIDS, but are recognized by
BIDS. For example, one can set ``datatype`` to ``dwi`` or ``func`` and
pass ``check=False`` to represent diffusion-weighted imaging and
functional MRI paths.
"""

def __init__(self, subject=None, session=None,
Expand Down Expand Up @@ -552,7 +557,8 @@ def update(self, *, check=None, **kwargs):
continue

if key == 'datatype':
if val is not None and val not in ALLOWED_DATATYPES:
if val is not None and val not in ALLOWED_DATATYPES \
and self.check:
raise ValueError(f'datatype ({val}) is not valid. '
f'Should be one of '
f'{ALLOWED_DATATYPES}')
Expand Down
8 changes: 6 additions & 2 deletions mne_bids/tests/test_path.py
Expand Up @@ -504,9 +504,13 @@ def test_bids_path(return_bids_test_dir):
suffix=suffix, check=False)

# also inherits error check from instantiation
# always error check datatype
# always error check entities though
with pytest.raises(ValueError, match='Key must be one of'):
bids_path.copy().update(blah='blah-entity')

# error check datatype if check is turned back on
with pytest.raises(ValueError, match='datatype .* is not valid'):
bids_path.copy().update(datatype=error_kind)
bids_path.copy().update(check=True, datatype=error_kind)

# does not error check on space if check=False ...
BIDSPath(subject=subject_id, space='foo', suffix='eeg', check=False)
Expand Down

0 comments on commit a2b0350

Please sign in to comment.