Skip to content

Conversation

evansd
Copy link
Contributor

@evansd evansd commented Sep 26, 2025

This adds support for getting the absolute value of a numeric series.

The motivating use case is being able easily to check whether two dates are within a certain range of each other without caring which comes first (see the related thread).

Note that we've chosen not to support the standard Python builtin abs() here. While that will be more familiar to experienced Python users, it's weirdly inconsistent with the rest of ehrQL which uses methods over function calls. Given that only a minority of our users are experienced with Python we've generally chosen to prioritise internal consistency over being Pythonic.

To avoid confusing more experienced users we make the abs() function raise an explicit error when called with a numeric series which points the user to the .absolute() method.

We can always revisit this decision later if needed.

Closes #2544

Copy link

cloudflare-workers-and-pages bot commented Sep 26, 2025

Deploying databuilder-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: ef6b6ab
Status: ✅  Deploy successful!
Preview URL: https://580e17ee.databuilder.pages.dev
Branch Preview URL: https://evansd-abs.databuilder.pages.dev

View logs

evansd added 4 commits October 1, 2025 14:28
The `abs()` builtin is the Pythonic way of taking the absolute value,
but the inconsistency with other ehrQL methods is potentially confusing
for our users, most of whom are not experienced Python programmers.

We could support both options, but this risks confusion. So instead we
raise an error for anyone trying to use the builtin which points them in
the right direction.
@evansd evansd enabled auto-merge October 1, 2025 13:29
@evansd evansd merged commit 6e0898c into main Oct 1, 2025
9 checks passed
@evansd evansd deleted the evansd/abs branch October 1, 2025 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support the abs() function for getting absolute values
2 participants