Skip to content

Commit 7ac7a41

Browse files
authored
Merge pull request #19 from Bayer-Group/issue14
Issue14
2 parents cd3f117 + 6c927a4 commit 7ac7a41

11 files changed

+700
-249
lines changed

docs/tutorials/CodelistPhenotype_Tutorial.ipynb

+9-9
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
"metadata": {},
115115
"outputs": [],
116116
"source": [
117-
"from phenex.phenotypes.codelist_phenotype import CodelistPhenotype\n",
117+
"from phenex.phenotypes import CodelistPhenotype\n",
118118
"# Ex.1 \n",
119119
"# Which patients had an atrial fibrillation diagnosis at **any time** in the data source?\n",
120120
"af_phenotype = CodelistPhenotype(\n",
@@ -197,7 +197,7 @@
197197
"outputs": [],
198198
"source": [
199199
"from phenex.phenotypes import CodelistPhenotype\n",
200-
"from phenex.operations.filters import (\n",
200+
"from phenex.filters import (\n",
201201
" GreaterThanOrEqualTo,\n",
202202
" LessThan,\n",
203203
" RelativeTimeRangeFilter, \n",
@@ -271,7 +271,7 @@
271271
"outputs": [],
272272
"source": [
273273
"from phenex.phenotypes import CodelistPhenotype\n",
274-
"from phenex.operations.filters import (\n",
274+
"from phenex.filters import (\n",
275275
" LessThanOrEqualTo,\n",
276276
" RelativeTimeRangeFilter\n",
277277
")\n",
@@ -337,7 +337,7 @@
337337
"outputs": [],
338338
"source": [
339339
"from phenex.phenotypes import CodelistPhenotype\n",
340-
"from phenex.operations.filters import (\n",
340+
"from phenex.filters import (\n",
341341
" CategoricalFilter\n",
342342
")\n",
343343
"\n",
@@ -368,7 +368,8 @@
368368
"metadata": {},
369369
"source": [
370370
"<a id='example_7'></a>\n",
371-
"#### Example 7"
371+
"# CURRENTLY NOT IMPLEMENTED\n",
372+
"#### ~Example 7~"
372373
]
373374
},
374375
{
@@ -379,7 +380,7 @@
379380
"outputs": [],
380381
"source": [
381382
"from phenex.phenotypes import CodelistPhenotype\n",
382-
"from phenex.operations.filters import (\n",
383+
"from phenex.filters import (\n",
383384
" CategoricalFilter\n",
384385
")\n",
385386
"\n",
@@ -429,7 +430,7 @@
429430
"outputs": [],
430431
"source": [
431432
"from phenex.phenotypes import CodelistPhenotype\n",
432-
"from phenex.operations.filters import (\n",
433+
"from phenex.filters import (\n",
433434
" LessThanOrEqualTo,\n",
434435
" RelativeTimeRangeFilter, \n",
435436
" CategoricalFilter\n",
@@ -499,8 +500,7 @@
499500
"outputs": [],
500501
"source": [
501502
"from phenex.phenotypes import CodelistPhenotype\n",
502-
"from phenex.phenotypes import CodelistPhenotype\n",
503-
"from phenex.operations.filters import (\n",
503+
"from phenex.filters import (\n",
504504
" LessThanOrEqualTo,\n",
505505
" RelativeTimeRangeFilter, \n",
506506
")\n",

phenex/filters/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
from .relative_time_range_filter import RelativeTimeRangeFilter
2+
from .value import GreaterThan, GreaterThanOrEqualTo, LessThan, LessThanOrEqualTo, EqualTo, Value

phenex/filters/categorical_filter.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ def __init__(
3030
self.domain = domain
3131
super(CategoricalFilter, self).__init__()
3232

33-
def _filter(self, table: Table):
34-
table = table.filter(table[self.column_name].isin(self.allowed_values))
35-
return table
33+
def _filter(self, table: 'PhenexTable'):
34+
return table.filter(table[self.column_name].isin(self.allowed_values))
35+
36+
def autojoin_filter(self, table: 'PhenexTable', tables:dict = None):
37+
if self.column_name not in table.columns:
38+
if self.domain not in tables.keys():
39+
raise ValueError(f"Table required for categorical filter ({self.domain}) does not exist within domains dicitonary")
40+
table = table.join(tables[self.domain], domains = tables)
41+
# TODO downselect to original columns
42+
return table.filter(table[self.column_name].isin(self.allowed_values))

phenex/filters/codelist_filter.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,5 @@ def _filter(self, code_table: CodeTable) -> CodeTable:
5858
code_table.columns
5959
)
6060

61-
return filtered_table.select(input_columns)
61+
# return table with downselected columns, of same type as input table
62+
return type(code_table)(filtered_table.select(input_columns))

0 commit comments

Comments
 (0)