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

Potential bug when using 'cutoff'-functionality #9

Closed WolfXeHD closed 2 years ago

WolfXeHD commented 2 years ago

Hi @valdezt , hi @MikeBusuttil ,

this is a great package many thanks for it! I think I might have discovered a bug. If this is not the case, please tell me why it is a feature:

Say we have:

import sigfig

value = 0.9656333507365017
uncert = 0.548083313468262

# then I call
rounded_result = sigfig.round(value, uncert, cutoff=19)
print(rounded_result) # prints '1.0 ± 0.6'

Another example:

import sigfig

value = 0.9656333507365017
uncert = 0.544083313468262

# notice the difference in the 3rd digit of the uncert variable

# then I call
rounded_result = sigfig.round(value, uncert, cutoff=19)
print(rounded_result) # prints '1.0 ± 0.5'

From a quick inspection of your code, I think it stems from this line where given['uncertainty'] is then the output of this line. I guess internally, given['uncertainty'] is overwritten to be the rounded number. But I am unsure if this is the behavior that you actually want?

Or is this intended and I overlooked something in your documentation?

Cheers, Tim

MikeBusuttil commented 2 years ago

Thanks Tim, good catch, that's a bug. I'll work on a fix and let you know when its merged.

MikeBusuttil commented 2 years ago

Hey Tim, the fix has been merged. You can update sigfig by running pip3 install sigfig -U in your terminal. Give it a whirl and let me know if that solves your issue. Thanks again for bringing that to our attention. Regards, -Mike

WolfXeHD commented 2 years ago

Hi Mike, the example that I posted above seems to be fixed. But I wonder why there is no update to the repo here? I would be interested in how you fixed it.

I am also wondering if one should use a continuous integration for the tests (and extend the tests). This is a prime example which one could have spotted with functioning unittests. On another note: Can you tell me how to run the tests locally? Cheers, Tim

MikeBusuttil commented 2 years ago

The main repo is at https://github.com/drakegroup/sigfig

CI test integration would of course be best practice. However, the test case for your special example didn't exist until you raised it. We have unit tests for most known cases and edge cases, feel free to suggest some more.

To run test locally:

WolfXeHD commented 2 years ago

Great! Thanks for the clarification!