Skip to content

Commit

Permalink
[FIX] Detect categorical column based on annotations (#154)
Browse files Browse the repository at this point in the history
* Detect categorical column based on Annotations

* Ensure BIDS levels alone doesn't pass as categorical
  • Loading branch information
surchs authored Jun 10, 2023
1 parent dd54f14 commit e1d6913
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bagel/pheno_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def is_missing_value(

def is_column_categorical(column: str, data_dict: dict) -> bool:
"""Determine whether a column in a Neurobagel data dictionary is categorical"""
if "Levels" in data_dict[column]:
if "Levels" in data_dict[column]["Annotations"]:
return True
return False

Expand Down
35 changes: 35 additions & 0 deletions bagel/tests/test_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,41 @@ def test_get_transformed_categorical_value(test_data, load_test_json):
)


@pytest.mark.parametrize(
"example,expected_result",
[
(
{
"column": {
"Annotations": {
"IsAbout": {"TermURL": "something", "Labels": "other"},
"Levels": {
"val1": {"TermURL": "something", "Label": "other"}
},
}
}
},
True,
),
(
{
"column": {
"Levels": {"val1": "some description"},
"Annotations": {
"IsAbout": {"TermURL": "something", "Labels": "other"}
},
}
},
False,
),
],
)
def test_detect_categorical_column(example, expected_result):
result = putil.is_column_categorical(column="column", data_dict=example)

assert result is expected_result


@pytest.mark.parametrize(
"value,column,expected",
[
Expand Down

0 comments on commit e1d6913

Please sign in to comment.