Skip to content

Commit

Permalink
changed test backend to duckdb
Browse files Browse the repository at this point in the history
  • Loading branch information
a-hartens committed Nov 14, 2024
1 parent 6c2b507 commit dd0d7dc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
2 changes: 0 additions & 2 deletions phenex/filters/aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ def aggregate(self, input_table: Table):
_aggregation_column = getattr(input_table, self.aggregation_column)

ibis.options.interactive = True
print(input_table)
# Define the window specification
window_spec = ibis.window(group_by=_aggregation_index_cols)

Expand All @@ -98,7 +97,6 @@ def aggregate(self, input_table: Table):
elif self.aggregation_function == "mean":
aggregation = _aggregation_column.mean().over(window_spec)
elif self.aggregation_function == "max":
print("DOING MAX")
aggregation = _aggregation_column.max().over(window_spec)
elif self.aggregation_function == "min":
aggregation = _aggregation_column.min().over(window_spec)
Expand Down
31 changes: 28 additions & 3 deletions phenex/test/phenotype_test_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pandas as pd
import ibis
import ibis.expr.datatypes as dt
from pyarrow import int8

from .util.check_equality import check_equality

Expand All @@ -25,7 +26,7 @@ class PhenotypeTestGenerator:

def run_tests(self, verbose=False):
self.verbose = verbose
self.con = ibis.sqlite.connect()
self.con = ibis.duckdb.connect()
self._create_artifact_directory(self.name_space)
self._create_input_data()
self._run_tests()
Expand Down Expand Up @@ -69,10 +70,21 @@ def _create_input_data(self):
# seed data dates in pandas datetime format and let the
# TestGenerator format them into strings.
input_info["df"].to_csv(path, index=False, date_format=self.date_format)

schema = {}
for col in input_info["df"].columns:
if 'date' in col.lower():
schema[col] = datetime.date
elif 'value' in col.lower():
schema[col] = float
else:
schema[col] = str

self.domains[input_info["name"]] = self.con.create_table(
input_info["name"], input_info["df"]
input_info["name"], input_info["df"], schema = schema
)


def _run_tests(self):
def df_from_test_info(test_info):
df = pd.DataFrame()
Expand Down Expand Up @@ -124,8 +136,21 @@ def df_from_test_info(test_info):
path, index=False, date_format=self.date_format
)


schema = {}
for col in df.columns:
if 'date' in col.lower():
schema[col] = datetime.date
elif 'value' in col.lower():
schema[col] = float
elif 'boolean' in col.lower():
schema[col] = bool
else:
schema[col] = str

expected_output_table = self.con.create_table(
self.name_output_file(test_info), df
self.name_output_file(test_info), df, schema=schema

)

join_on = ['PERSON_ID']
Expand Down
2 changes: 1 addition & 1 deletion phenex/test/phenotypes/test_measurement_phenotype.py
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ def test_measurement_phenotype_return_values():

def test_measurement_phenotype_value_aggregation():
spg = MeasurementPhenotypeValueAggregationTestGenerator()
spg.run_tests(verbose=True)
spg.run_tests(verbose=False)


if __name__ == "__main__":
Expand Down

0 comments on commit dd0d7dc

Please sign in to comment.