Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/whats_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ The following authors had contributed before. Thank you for sticking around!
* `Stefan Appelhoff`_
* `Daniel McCloy`_
* `Scott Huberty`_
* `Pierre Guetschel`_

Detailed list of changes
~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -57,6 +58,7 @@ Detailed list of changes
- BIDS dictates that the recording entity should be displayed as "_recording-" in the filename. This PR makes :class:`mne_bids.BIDSPath` correctly display "_recording-" (instead of "_rec-") in BIDSPath.fpath. By `Scott Huberty`_ (:gh:`1348`)
- :func:`mne_bids.make_dataset_description` now correctly encodes the dataset description as UTF-8 on disk, by `Scott Huberty`_ (:gh:`1357`)
- Corrects extension when filtering filenames in :meth:`mne_bids.BIDSPath.match()` and :func:`mne_bids.find_matching_paths()`, by `Arne Gottwald` (:gh:`1355`)
- Fix :class:`mne_bids.BIDSPath` partially matching a value, by `Pierre Guetschel` (:gh:`1388`)

⚕️ Code health
^^^^^^^^^^^^^^
Expand Down
4 changes: 3 additions & 1 deletion mne_bids/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -1390,7 +1390,9 @@ def _get_matching_bidspaths_from_filesystem(bids_path):
search_str = op.join(search_str, datatype)
else:
search_str = op.join(search_str, "**")
search_str = op.join(search_str, f"{basename}*")
# The basename should end with a separator "_" or a period "."
# to avoid matching only the beggining of a value.
search_str = op.join(search_str, f"{basename}[_.]*")

# Find all matching files in all supported formats.
valid_exts = ALLOWED_FILENAME_EXTENSIONS
Expand Down
23 changes: 23 additions & 0 deletions mne_bids/tests/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -1648,3 +1648,26 @@ def test_dont_create_dirs_on_fpath_access(tmp_path):
bp = BIDSPath(subject="01", datatype="eeg", root=tmp_path)
bp.fpath # accessing .fpath is required for this regression test
assert not (tmp_path / "sub-01").exists()


def test_fpath_common_prefix(tmp_path):
"""Tests that fpath does not match multiple files with the same prefix.

This might happen if indices are not zero-paddded.
"""
sub_dir = tmp_path / "sub-1" / "eeg"
sub_dir.mkdir(exist_ok=True, parents=True)
(sub_dir / "sub-1_run-1_raw.fif").touch()
(sub_dir / "sub-1_run-2.edf").touch()
# Other valid BIDS paths with the same basename prefix:
(sub_dir / "sub-1_run-10_raw.fif").touch()
(sub_dir / "sub-1_run-20.edf").touch()

assert (
BIDSPath(root=tmp_path, subject="1", run="1").fpath
== sub_dir / "sub-1_run-1_raw.fif"
)
assert (
BIDSPath(root=tmp_path, subject="1", run="2").fpath
== sub_dir / "sub-1_run-2.edf"
)