Skip to content

Commit 3d14cdf

Browse files
authored
[FIX] pull sample_size metadata from study if not in analysis (#939)
* look into study as well as analysis for sample_size * fix style * fix docstring
1 parent 7098b16 commit 3d14cdf

4 files changed

Lines changed: 32 additions & 5 deletions

File tree

nimare/io.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,12 @@ def _analysis_to_dict(study, analysis):
6363
},
6464
}
6565

66-
sample_sizes = analysis.metadata.get("sample_sizes", None)
67-
sample_size = analysis.metadata.get("sample_size", None)
66+
sample_sizes = analysis.metadata.get("sample_sizes", None) or study.metadata.get(
67+
"sample_sizes", None
68+
)
69+
sample_size = analysis.metadata.get("sample_size", None) or study.metadata.get(
70+
"sample_size", None
71+
)
6872

6973
# Validate sample sizes if present
7074
if sample_sizes is not None and not isinstance(sample_sizes, (list, tuple)):

nimare/tests/conftest.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,20 @@ def testdata_ibma_resample(tmp_path_factory):
172172
return dset
173173

174174

175+
@pytest.fixture(scope="session")
176+
def sample_size_nimads_studyset():
177+
"""Download/lookup example NiMADS studyset."""
178+
out_file = os.path.join(get_test_data_path(), "sample_size_nimads_studyset.json")
179+
if not os.path.isfile(out_file):
180+
url = "https://neurostore.org/api/studysets/zvE8LEQHAJxV?nested=true"
181+
response = request("GET", url)
182+
with open(out_file, "wb") as f:
183+
f.write(response.content)
184+
with open(out_file, "r") as f:
185+
studyset = json.load(f)
186+
return studyset
187+
188+
175189
@pytest.fixture(scope="session")
176190
def example_nimads_studyset():
177191
"""Download/lookup example NiMADS studyset."""

nimare/tests/data/sample_size_nimads_studyset.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

nimare/tests/test_io.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ def test_convert_nimads_to_dataset_sample_sizes(
3838
assert "sample_sizes" in dset.metadata.columns
3939

4040

41-
def test_convert_nimads_to_dataset_single_sample_size(
42-
example_nimads_studyset, example_nimads_annotation
43-
):
41+
def test_convert_nimads_to_dataset_single_sample_size(example_nimads_studyset):
4442
"""Test conversion of nimads JSON to nimare dataset with a single sample size value."""
4543
studyset = Studyset(example_nimads_studyset)
4644
for study in studyset.studies:
@@ -53,6 +51,16 @@ def test_convert_nimads_to_dataset_single_sample_size(
5351
assert "sample_sizes" in dset.metadata.columns
5452

5553

54+
def test_convert_nimads_to_dataset_wonky_sample_size(sample_size_nimads_studyset):
55+
"""Test conversion of nimads JSON to nimare dataset with wonky sample size values."""
56+
studyset = Studyset(sample_size_nimads_studyset)
57+
58+
dset = io.convert_nimads_to_dataset(studyset)
59+
60+
assert isinstance(dset, nimare.dataset.Dataset)
61+
assert "sample_sizes" in dset.metadata.columns
62+
63+
5664
@pytest.mark.parametrize(
5765
"sample_sizes_val,sample_size_val,expect_col,expect_warning",
5866
[

0 commit comments

Comments
 (0)