Skip to content

Commit

Permalink
Use as_int() in measures series_as_int function
Browse files Browse the repository at this point in the history
  • Loading branch information
rebkwok committed Jan 16, 2025
1 parent 2070cb6 commit 2083302
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions ehrql/measures/calculate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from ehrql.measures.measures import get_all_group_by_columns
from ehrql.query_model.column_specs import ColumnSpec, get_column_spec_from_series
from ehrql.query_model.nodes import Case, Dataset, Function, Value, get_series_type
from ehrql.query_model.nodes import Dataset, Function, Value, get_series_type
from ehrql.query_model.transforms import substitute_parameters


Expand Down Expand Up @@ -207,15 +207,7 @@ def series_as_int(series):
if series_type is int:
return series
elif series_type is bool:
# TODO: This is definitely not the most efficient way to do this. We should
# extend the `CastToInt` operation to apply to boolean as well.
return Case(
{
Function.EQ(series, Value(True)): Value(1),
Function.EQ(series, Value(False)): Value(0),
},
default=None,
)
return Function.CastToInt(series)
else:
assert False

Expand Down

0 comments on commit 2083302

Please sign in to comment.