-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
feat: Add round_sig_figs
expression for rounding to significant figures
#11959
Conversation
Hi @owrior, thanks for the PR. Could you please make an issue so we can discuss whether we want to include this, and what the right API for it would be? Thanks! From a quick initial look, the boilerplate here looks quite good 👌 |
Refactored to round_sig_figs @orlp so think this might be ready! |
if value == 0.0 { | ||
return value; | ||
} | ||
let magnitiude = 10.0.pow(digits as f64 - 1.0 - ((value.abs()).log10().floor())); |
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.
Could you use f64::powi
? Also it's spelled magnitude
.
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.
Think this is done.
11c9ac9
to
a5b6dac
Compare
round_sig_figs
for rounding to significant figures
round_sig_figs
for rounding to significant figuresround_sig_figs
expression for rounding to significant figures
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.
I will do a small update to the docstrings, will update and merge after.
Recently I have been working on a project where we needed to round to significant figures and realised there is no way to do this in pandas, numpy or polars. I found this as the best solution.
However it would be nice to have it as part of a package. Would it be possible to include this? (The implementation here is about 20% faster than the numpy one here already but I imagine there is a better way of implementing it) (Update now about 45% faster).
Thank you!
Closes #11968