Skip to content

Commit

Permalink
functioning score phenotype tests with casting to int
Browse files Browse the repository at this point in the history
  • Loading branch information
a-hartens committed Nov 14, 2024
1 parent f02fe75 commit a92777c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
6 changes: 6 additions & 0 deletions phenex/phenotypes/computation_graph_phenotypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ def _execute(self, tables: Dict[str, Table]) -> PhenotypeTable:
PhenotypeTable: The resulting phenotype table containing the required columns.
"""
joined_table = hstack(self.children, tables['PERSON'].select('PERSON_ID'))

if self._populate == 'value' and self._operate_on == 'boolean':
for child in self.children:
column_name = f"{child.name}_BOOLEAN"
joined_table = joined_table.mutate(**{column_name: joined_table[column_name].cast(float)})

if self._populate == "value":
_expression = self.computation_graph.get_value_expression(
joined_table, operate_on=self._operate_on
Expand Down
2 changes: 1 addition & 1 deletion phenex/phenotypes/phenotype.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def manage_node(node):
elif isinstance(node, Phenotype):
if operate_on == "boolean":
return table[f"{node.name}_BOOLEAN"]
return table[f"{node.name}_vALUE"]
return table[f"{node.name}_VALUE"]
return node

left = manage_node(self.left)
Expand Down
25 changes: 16 additions & 9 deletions phenex/test/phenotypes/test_score_phenotype.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,17 @@ def define_input_tables(self):
code_type_columnname="CODE_TYPE",
event_date_columnname="EVENT_DATE",
)

df_person = pd.DataFrame()
df_person['PERSON_ID'] = df['PERSON_ID'].unique()
return [
{
"name": "CONDITION_OCCURRENCE",
"df": df,
},
{
"name": "PERSON",
"df": df_person
}
]

Expand Down Expand Up @@ -64,24 +71,24 @@ def define_phenotype_tests(self):

score1 = {
"name": "score1",
"persons": [f"P{x}" for x in range(1, 7)],
"values": [2, 2, 1, 1, 1, 1],
"persons": [f"P{x}" for x in range(1, 8)],
"values": [2, 2, 1, 1, 1, 1,0],
"phenotype": ScorePhenotype(expression=(c1["phenotype"] + c2["phenotype"])),
}

score2 = {
"name": "score2",
"persons": [f"P{x}" for x in range(1, 7)],
"values": [3, 3, 2, 2, 1, 1],
"persons": [f"P{x}" for x in range(1, 8)],
"values": [3, 3, 2, 2, 1, 1,0],
"phenotype": ScorePhenotype(
expression=(c1["phenotype"] * 2 + c2["phenotype"])
),
}

score3 = {
"name": "score3",
"persons": [f"P{x}" for x in range(1, 7)],
"values": [3, 3, 1, 1, 2, 2],
"persons": [f"P{x}" for x in range(1, 8)],
"values": [3, 3, 1, 1, 2, 2,0],
"phenotype": ScorePhenotype(
expression=(c1["phenotype"] + c2["phenotype"] * 2)
),
Expand All @@ -107,8 +114,8 @@ def define_phenotype_tests(self):

score6 = {
"name": "score6",
"persons": [f"P{x}" for x in range(1, 7)],
"values": [3, 3, 1, 1, 2, 2],
"persons": [f"P{x}" for x in range(1, 8)],
"values": [3, 3, 1, 1, 2, 2,0],
"phenotype": ScorePhenotype(expression=(c1["phenotype"] * c2["phenotype"])),
}

Expand All @@ -122,7 +129,7 @@ def define_phenotype_tests(self):

def test_score_phenotype():
tg = ScorePhenotypeTestGenerator()
# tg.run_tests()
tg.run_tests()


if __name__ == "__main__":
Expand Down

0 comments on commit a92777c

Please sign in to comment.