Skip to content

Commit 2d6202b

Browse files
committed
FIX: Stop assuming age units
Rather than default to 'months', any `age` values found without an accompanying JSON describing the `age.Units` will be treated as missing data.
1 parent 37b8c5e commit 2d6202b

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

nibabies/utils/bids.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88
import os
99
import sys
1010
import typing as ty
11-
import warnings
1211
from pathlib import Path
1312

14-
SUPPORTED_AGE_UNITS = ('weeks', 'months', 'years')
13+
SUPPORTED_AGE_UNITS = (
14+
'weeks',
15+
'months',
16+
'years',
17+
)
1518

1619

1720
def write_bidsignore(deriv_dir):
@@ -289,11 +292,7 @@ def _get_age_from_tsv(
289292
bids_json = bids_tsv.with_suffix('.json')
290293
age_units = _get_age_units(bids_json)
291294
if age_units is False:
292-
warnings.warn(
293-
f'Could not verify age units for file: {bids_tsv}',
294-
stacklevel=1,
295-
)
296-
age_units = 'months'
295+
return None
297296
else:
298297
age_units = age_col.split('_')[-1]
299298

@@ -307,11 +306,13 @@ def _get_age_units(bids_json: Path) -> ty.Literal['weeks', 'months', 'years', Fa
307306
except (json.JSONDecodeError, OSError):
308307
return False
309308

310-
# See if the unit is listed
311-
units = data.get('age', {}).get('Units')
312-
for unit in units:
313-
if unit.lower() in SUPPORTED_AGE_UNITS:
314-
return unit
309+
units = data.get('age', {}).get('Units', '')
310+
if not isinstance(units, str):
311+
# Multiple units consfuse us
312+
return False
313+
314+
if units.lower() in SUPPORTED_AGE_UNITS:
315+
return units.lower()
315316
return False
316317

317318

0 commit comments

Comments
 (0)