Skip to content

Commit 032d79e

Browse files
committed
fixed measurement and codelist phenotype tests
1 parent 42a3f16 commit 032d79e

File tree

5 files changed

+19
-8
lines changed

5 files changed

+19
-8
lines changed

phenex/codelists/codelists.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
from typing import Dict, List, Union, Optional
3+
import pandas as pd
34

45

56
class Codelist:
@@ -149,8 +150,15 @@ def __repr__(self):
149150
codelist={self.codelist}
150151
)"""
151152

153+
def to_pandas(self) -> pd.DataFrame:
154+
"""
155+
Convert the codelist to a pandas DataFrame.
156+
"""
157+
158+
_df = pd.DataFrame(self.to_tuples(), columns=["code_type", "code"])
159+
_df['codelist'] = self.name
160+
return _df
152161

153-
import pandas as pd
154162

155163

156164
class LocalCSVCodelistFactory:

phenex/filters/aggregator.py

+3
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,13 @@ def aggregate(self, input_table: Table):
4646

4747
# Apply the distinct reduction if required
4848
if self.reduce:
49+
print("REDUCING")
4950
selected_columns = self.aggregation_index + [self.event_date_column]
5051
input_table = input_table.select(selected_columns).distinct()
52+
print(selected_columns)
5153
input_table = input_table.mutate(VALUE=ibis.null())
5254

55+
print(input_table.to_pandas())
5356
return input_table
5457

5558
class Nearest(VerticalDateAggregator):

phenex/phenotypes/codelist_phenotype.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,13 @@ def _perform_time_filtering(self, code_table):
110110
code_table = rtr.filter(code_table)
111111
return code_table
112112

113-
def _perform_date_selection(self, code_table):
113+
def _perform_date_selection(self, code_table, reduce=True):
114114
if self.return_date is None or self.return_date == "all":
115115
return code_table
116116
if self.return_date == "first":
117-
aggregator = First()
117+
aggregator = First(reduce=reduce)
118118
elif self.return_date == "last":
119-
aggregator = Last()
119+
aggregator = Last(reduce=reduce)
120120
else:
121121
raise ValueError(f"Unknown return_date: {self.return_date}")
122122
return aggregator.aggregate(code_table)

phenex/phenotypes/measurement_phenotype.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def _execute(self, tables) -> PhenotypeTable:
114114
code_table = tables[self.domain]
115115
code_table = self._perform_codelist_filtering(code_table)
116116
code_table = self._perform_time_filtering(code_table)
117-
code_table = self._perform_date_selection(code_table)
117+
code_table = self._perform_date_selection(code_table, reduce=False)
118118
code_table = self._perform_nonphysiological_value_filtering(code_table)
119119
code_table = self._perform_value_aggregation(code_table)
120120
code_table = self._perform_value_filtering(code_table)

phenex/test/phenotypes/test_codelist_phenotype.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,6 @@ def test_codelist_phenotype():
547547

548548
if __name__ == "__main__":
549549
test_codelist_phenotype()
550-
test_relative_time_range_filter()
551-
test_anchor_phenotype()
552-
test_return_date()
550+
# test_relative_time_range_filter()
551+
# test_anchor_phenotype()
552+
# test_return_date()

0 commit comments

Comments
 (0)