Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deduplicate wildcards when parsing components #455

Merged
merged 1 commit into from
Jul 29, 2024
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: 1 addition & 1 deletion snakebids/core/input_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ def _get_component(
for img in matching_files:
wildcards: list[str] = [
wildcard
for wildcard in component.get("wildcards", [])
for wildcard in set(component.get("wildcards", []))
if wildcard in img.entities
]
_logger.debug("Wildcards %s found entities for %s", wildcards, img.path)
Expand Down
29 changes: 29 additions & 0 deletions snakebids/tests/test_generate_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,35 @@ def test_filter_with_invalid_method_raises_error(self, tmpdir: Path, method: str
generate_inputs(tmpdir, pybids_inputs)


@settings(
deadline=800,
suppress_health_check=[
HealthCheck.function_scoped_fixture,
HealthCheck.too_slow,
],
max_examples=1,
)
@given(dataset=sb_st.datasets_one_comp(unique=True))
def test_duplicate_wildcards_does_not_create_error(
dataset: BidsDataset, bids_fs: Path, fakefs_tmpdir: Path
):
root = tempfile.mkdtemp(dir=fakefs_tmpdir)
rooted = BidsDataset.from_iterable(
attrs.evolve(comp, path=os.path.join(root, comp.path))
for comp in dataset.values()
)
create_dataset(Path("/"), rooted)
config = create_snakebids_config(dataset)
wildcards = itx.first(config.values()).get("wildcards", [])
wildcards.append(wildcards[0])
reindexed = generate_inputs(
root,
config,
)
assert reindexed == rooted
assert reindexed.layout is not None


class TestAbsentConfigEntries:
def get_entities(self, root: Path):
# Generate directory
Expand Down
Loading