valdezt / sigfig

A python module aimed to aid the user with visual display of scientific numbers, i.e. significant figures, rounding, spacing, etc.
12 stars 4 forks source link

User Warning for more sigfigs than digits #7

Open freiburgermsu opened 2 years ago

freiburgermsu commented 2 years ago

Hello!

Large workflow applications of sigfig often contain values that have less digits than requested sigfigs, which launches this error in sigfig:

{sigfigs} significant figures requested from number with only {digits} significant figures

Can the error be optionally ignored, or can the code be expanded to create trailing zeros for instances where more sigfigs are requested than digits exist in a value?

MikeBusuttil commented 2 years ago

Hey @freiburgermsu thanks for reaching out.

The best way to suppress warnings is with Python's built-in warning control library

>>> from warnings import filterwarnings
>>> filterwarnings('ignore')

However, we have implemented built-in warning suppression in the latest version with the warn keyword if you prefer that interface

$ pip install sigfig -U
$ py
>>> from sigfig import round
>>> round('12', sigfigs=5, warn=False)
'12.000'

just make sure your results are strings instead of floats since Python's built-in float implementation will hide those extra zero's

>>> round(12, sigfigs=5, warn=False)
12

Regards, -Mike

freiburgermsu commented 2 years ago

Hello Mike,

The warn argument is phenomenal. I implement it now.

Thank you for your support :)