Skip to content

Commit

Permalink
Expand paths unaltered when comp has no wcards
Browse files Browse the repository at this point in the history
Previously returned an empty list. This is different from a component
with no entries (but with wildcards), which should return an empty list

Resolves #371
  • Loading branch information
pvandyken committed Feb 20, 2024
1 parent d1031ff commit e15a2f1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
21 changes: 12 additions & 9 deletions snakebids/core/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,17 +394,20 @@ def sequencify(item: bool | str | Iterable[str]) -> bool | list[str]:
return list(itx.always_iterable(item))

allow_missing_seq = sequencify(allow_missing)
inner_expand = list(
# order preserving deduplication
dict.fromkeys(
sn_expand(
list(itx.always_iterable(paths)),
zip,
allow_missing=True if wildcards else allow_missing_seq,
**self.zip_lists,
if self.zip_lists:
inner_expand = list(
# order preserving deduplication
dict.fromkeys(
sn_expand(
list(itx.always_iterable(paths)),
zip,
allow_missing=True if wildcards else allow_missing_seq,
**self.zip_lists,
)
)
)
)
else:
inner_expand = list(itx.always_iterable(paths))
if not wildcards:
return inner_expand

Expand Down
10 changes: 10 additions & 0 deletions snakebids/tests/test_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,16 @@ def test_expand_preserves_entry_order(self, component: Expandable):
for path, entity_vals in zip(paths, zip(*component.zip_lists.values())):
assert bids(**dict(zip(component.zip_lists.keys(), entity_vals))) == path

@given(path=st.text())
def test_expandable_with_no_wildcards_returns_path_unaltered(self, path: str):
component = BidsPartialComponent(zip_lists={})
assert itx.one(component.expand(path)) == path

@given(component=sb_st.expandables(min_values=0, max_values=0, path_safe=True))
def test_expandable_with_no_entries_returns_empty_list(self, component: Expandable):
path_tpl = bids(**get_wildcard_dict(component.zip_lists))
assert component.expand(path_tpl) == []


class TestBidsComponentExpand:
"""
Expand Down

0 comments on commit e15a2f1

Please sign in to comment.