Skip to content

Commit

Permalink
Eliminate deprecated code
Browse files Browse the repository at this point in the history
Remove existing references to the deprecated BidsDataset properties.
Some functions, including the tests of these properties, call them by
necessity, so DeprecationWarnings are ignored at these points
  • Loading branch information
pvandyken committed Feb 18, 2023
1 parent b7e4ea6 commit c47586f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 38 deletions.
29 changes: 14 additions & 15 deletions snakebids/core/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import itertools as it
import operator as op
import warnings
from collections import UserDict
from string import Formatter
from typing import TYPE_CHECKING, Any, Iterable, Optional, Union, cast
Expand Down Expand Up @@ -289,9 +290,7 @@ def subjects(self):
return [
*{
*it.chain.from_iterable(
input_list["subject"]
for input_list in self.entities.values()
if "subject" in input_list
component.entities.get("subject", []) for component in self.values()
)
}
]
Expand All @@ -302,9 +301,7 @@ def sessions(self):
return [
*{
*it.chain.from_iterable(
input_list["session"]
for input_list in self.entities.values()
if "session" in input_list
component.entities.get("session", []) for component in self.values()
)
}
]
Expand Down Expand Up @@ -334,15 +331,17 @@ def as_dict(self):
-------
BidsDatasetDict
"""
return BidsDatasetDict(
input_path=self.input_path,
input_lists=self.entities,
input_wildcards=self.input_wildcards,
input_zip_lists=self.input_zip_lists,
subjects=self.subjects,
sessions=self.sessions,
subj_wildcards=self.subj_wildcards,
)
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=DeprecationWarning)
return BidsDatasetDict(
input_path=self.input_path,
input_lists=self.entities,
input_wildcards=self.input_wildcards,
input_zip_lists=self.input_zip_lists,
subjects=self.subjects,
sessions=self.sessions,
subj_wildcards=self.subj_wildcards,
)

@classmethod
def from_iterable(cls, iterable: Iterable[BidsComponent]):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@ wildcard_constraints: **snakebids.get_wildcard_constraints(config['pybids_input


rule smooth:
input: inputs.path['bold']
input: inputs['bold'].path
output:
bids(
root=config['root'],
datatype='func',
desc='smooth{fwhm}mm',
suffix='bold.nii.gz',
**inputs.wildcards['bold']
**inputs['bold'].wildcards
)
container: config['singularity']['fsl']
log:
bids(
root='logs',
suffix='smooth.log',
fwhm='{fwhm}',
**inputs.wildcards['bold']
**inputs['bold'].wildcards
)
params: sigma = lambda wildcards: f'{float(wildcards.fwhm)/2.355:0.2f}'
shell: 'fslmaths {input} -s {params.sigma} {output}'
Expand All @@ -56,6 +56,6 @@ rule all:
allow_missing=True,
),
zip,
**inputs.zip_lists['bold']
**inputs['bold'].zip_lists
)
default_target: True
13 changes: 8 additions & 5 deletions snakebids/tests/test_datasets.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import copy
import itertools as it
import warnings
from typing import Any, Dict, List

import more_itertools as itx
Expand Down Expand Up @@ -31,11 +32,13 @@ def test_bids_component_aliases_are_correctly_set(self, component: BidsComponent

@given(sb_st.bids_components())
def test_bids_dataset_aliases_are_correctly_set(self, component: BidsComponent):
dataset = BidsDataset.from_iterable([component])
assert dataset.input_path == dataset.path
assert dataset.input_zip_lists == dataset.zip_lists
assert dataset.input_lists == dataset.input_lists
assert dataset.input_wildcards == dataset.wildcards
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=DeprecationWarning)
dataset = BidsDataset.from_iterable([component])
assert dataset.input_path == dataset.path
assert dataset.input_zip_lists == dataset.zip_lists
assert dataset.input_lists == dataset.input_lists
assert dataset.input_wildcards == dataset.wildcards


class TestBidsComponentValidation:
Expand Down
25 changes: 11 additions & 14 deletions snakebids/tests/test_generate_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ def tmpdir(self, fakefs_tmpdir: Path):

def disambiguate_components(self, dataset: BidsDataset):
assert len(dataset) == 2
dataset.zip_lists
comp1, comp2 = dataset.values()
return sorted([comp1, comp2], key=lambda comp: len(comp.entities.keys()))

Expand Down Expand Up @@ -271,9 +270,7 @@ def test_missing_filters(self, tmpdir: Path):
pybids_config=str(Path(__file__).parent / "data" / "custom_config.json"),
use_bids_inputs=True,
)
template = BidsDataset(
{"t1": BidsComponent("t1", config.input_path["t1"], zip_list)}
)
template = BidsDataset({"t1": BidsComponent("t1", config["t1"].path, zip_list)})
# Order of the subjects is not deterministic
assert template == config
assert config.subj_wildcards == {"subject": "{subject}"}
Expand All @@ -297,7 +294,7 @@ def test_missing_wildcards(self, tmpdir: Path):
pybids_config=str(Path(__file__).parent / "data" / "custom_config.json"),
use_bids_inputs=True,
)
template = BidsDataset({"t1": BidsComponent("t1", config.input_path["t1"], {})})
template = BidsDataset({"t1": BidsComponent("t1", config["t1"].path, {})})
assert template == config
assert config.subj_wildcards == {"subject": "{subject}"}

Expand Down Expand Up @@ -573,7 +570,7 @@ def test_custom_pybids_config(tmpdir: Path):
}
)
assert template == result
assert result.input_wildcards == {"t1": {"foo": "{foo}", "subject": "{subject}"}}
assert result["t1"].wildcards == {"foo": "{foo}", "subject": "{subject}"}
# Order of the subjects is not deterministic
assert result.subj_wildcards == {"subject": "{subject}"}

Expand Down Expand Up @@ -647,7 +644,7 @@ def test_t1w():
{
"t1": BidsComponent(
"t1",
result.input_path["t1"],
result["t1"].path,
{"acq": ["mprage", "mprage"], "subject": ["001", "002"]},
)
}
Expand Down Expand Up @@ -678,14 +675,16 @@ def test_t1w():
participant_label="001",
use_bids_inputs=True,
)
assert result.entities == {
"scan": {"acq": ["mprage"], "subject": ["001"], "suffix": ["T1w"]}
assert result["scan"].entities == {
"acq": ["mprage"],
"subject": ["001"],
"suffix": ["T1w"],
}
template = BidsDataset(
{
"scan": BidsComponent(
"scan",
result.input_path["scan"],
result["scan"].path,
{
"acq": [
"mprage",
Expand Down Expand Up @@ -751,15 +750,13 @@ def test_t1w():
{
"t1": BidsComponent(
"t1",
result.input_path["t1"],
result["t1"].path,
{
"acq": ["mprage", "mprage"],
"subject": ["001", "002"],
},
),
"t2": BidsComponent(
"t2", result.input_path["t2"], {"subject": ["002"]}
),
"t2": BidsComponent("t2", result["t2"].path, {"subject": ["002"]}),
}
)
# Order of the subjects is not deterministic
Expand Down

0 comments on commit c47586f

Please sign in to comment.