jagerber48 / sciform

A package for formatting numbers into scientific formatted strings.
https://sciform.readthedocs.io/en/stable/
MIT License
14 stars 2 forks source link

Idea: have a `fallback_ndigits` option #177

Open jagerber48 opened 1 month ago

jagerber48 commented 1 month ago

Right now for value/uncertainty formatting sciform first looks to the uncertainty to determine the decimal place to which the value and uncertainty should be rounded and displayed. sciform succeeds if the uncertainty is non-zero and finite. If the uncertainty is zero or non-finite (recall non-finite includes nan) then it falls back to the value to determine the decimal place to which to round. Typically sciform is configured to round to one or two digits of uncertainty, or use the PDG rounding convention. This means the value will be rounded the same. However, this is a little strange because, for example, the PDG rules are meant to apply to uncertainty, not values.

This issue proposes a new option called fallback_ndigits which instructs sciform how to behave in this fallback scenario. Options would be

jagerber48 commented 1 month ago

More thoughts on this:

Without any such fallback feature the user could easily write two of their own Formatters, detect if their uncertainty is zero or non-finite and select which formatter to use based on that. One general way this approach could be wrapped into sciform is to have an entire fallback formatter. In the event the uncertainty is invalid the fallback formatter could be merged into the main formatter and the result could be used. It's an open question which formatter should be used if both the uncertainty and value are invalid.