Skip to content

Commit b8c21a5

Browse files
committed
BUG: Fix bug with path search
1 parent 7b04694 commit b8c21a5

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

mne_bids/path.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,6 +2014,8 @@ def get_entity_vals(
20142014
ignore_suffixes : str | array-like of str | None
20152015
Suffixes to ignore. If ``None``, include all suffixes. This can be helpful for
20162016
ignoring non-data sidecars such as `*_scans.tsv` or `*_coordsystem.json`.
2017+
2018+
.. versionadded:: 0.17
20172019
include_match : str | array-like of str | None
20182020
Apply a starting match pragma following Unix style pattern syntax from
20192021
package glob to prefilter search criterion.
@@ -2542,24 +2544,19 @@ def _return_root_paths(root, datatype=None, ignore_json=True, ignore_nosub=False
25422544

25432545
if datatype is None and not ignore_nosub:
25442546
search_str = "*.*"
2545-
paths = root.rglob(search_str)
25462547
else:
25472548
if datatype is not None:
25482549
datatype = _ensure_tuple(datatype)
2549-
search_str = f"**/{'|'.join(datatype)}/.*"
2550+
search_str = f"**/{'|'.join(datatype)}/*.*"
25502551
else:
25512552
search_str = "**/*.*"
25522553

25532554
# only browse files which are of the form root/sub-*,
25542555
# such that we truely only look in 'sub'-folders:
2555-
25562556
if ignore_nosub:
2557-
search_str = "sub-*/" + search_str
2557+
search_str = f"sub-*/{search_str}"
25582558

2559-
paths = [
2560-
Path(root, fn)
2561-
for fn in glob.iglob(search_str, root_dir=root, recursive=True)
2562-
]
2559+
paths = root.rglob(search_str)
25632560

25642561
# Only keep files (not directories), ...
25652562
# and omit the JSON sidecars if `ignore_json` is True.

mne_bids/tests/test_path.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ def test_filter_fnames(entities, expected_n_matches):
10461046

10471047

10481048
@testing.requires_testing_data
1049-
def test_match(return_bids_test_dir):
1049+
def test_match_basic(return_bids_test_dir):
10501050
"""Test retrieval of matching basenames."""
10511051
bids_root = Path(return_bids_test_dir)
10521052

@@ -1140,6 +1140,27 @@ def test_match(return_bids_test_dir):
11401140
bids_path_01.fpath.unlink() # clean up created file
11411141

11421142

1143+
def test_match_advanced(tmp_path):
1144+
"""Test additional match functionality."""
1145+
bids_root = tmp_path
1146+
fnames = (
1147+
"sub-01/nirs/sub-01_task-tapping_events.tsv",
1148+
"sub-02/nirs/sub-02_task-tapping_events.tsv",
1149+
)
1150+
for fname in fnames:
1151+
this_path = Path(bids_root / fname)
1152+
this_path.parent.mkdir(parents=True, exist_ok=True)
1153+
this_path.touch()
1154+
path = BIDSPath(
1155+
root=bids_root,
1156+
datatype="nirs",
1157+
suffix="events",
1158+
extension=".tsv",
1159+
)
1160+
matches = path.match()
1161+
assert len(matches) == len(fnames), path
1162+
1163+
11431164
@testing.requires_testing_data
11441165
def test_find_matching_paths(return_bids_test_dir):
11451166
"""We test by yielding the same results as BIDSPath.match().

0 commit comments

Comments
 (0)