-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support as_int on bool series #2359
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good, although because it's so end-user focused I'd like to see some more documentation - e.g. it should definitely be mentioned in https://docs.opensafely.org/ehrql/reference/features/#7-operations-on-boolean-series & maybe also as an alternative option in https://docs.opensafely.org/ehrql/reference/features/#1113-case-with-boolean-column ?
25333ce
to
e4e4ce0
Compare
Thanks, I'd forgotten to add the new spec test file to the toc.py so the reference docs weren't being pulled in. Also added a comment in the case spec test. |
Deploying databuilder-docs with Cloudflare Pages
|
wow, not sure I'd really seen that test/docs tooling, that's brill (& the docs look much better now thanks) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thanks for doing this!
One other thing it might be worth doing (non-urgently) is extending this bit of the generative tests so it produces examples of bools being cast to ints:
ehrql/tests/generative/variable_strategies.py
Lines 290 to 293 in b4adab2
@st.composite | |
def cast_to_int(draw, type_, frame): | |
type_ = draw(any_numeric_type()) | |
return Function.CastToInt(draw(series(type_, frame))) |
We've got code in the tests which will moan at you if you add a completely new operation and don't include it in the generative tests. But we don't have anything which reminds you to update the tests if you extend an existing operation (I don't quite know how we'd do that to be honest) so it's one of those things which we inevitably forget.
@@ -376,7 +376,7 @@ class FloorDivide(Series[int]): | |||
|
|||
# Casting numeric types | |||
class CastToInt(Series[int]): | |||
source: Series[Numeric] | |||
source: Series[Numeric] | Series[bool] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could save eight whole characters by writing this as:
Series[Numeric | bool]
Eight, Becky! What were you thinking?
Fixes #1313
is_int
on a bool series