-
Notifications
You must be signed in to change notification settings - Fork 39
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
adding functions to manage rounding #144
Conversation
Hi @cippy, thanks a lot for this contribution! The tests show some failures, one related to the rounding, the other one simply being a linter error. Do you think you will be able to fix them yourself or would you like some help with it? Do you think you could come up with some tests for the new functions? Also here: if you would like some help or advice, let me know! |
Hi, I see other errors are related to style in naming variables or not using spaces after commas, will try to fix them and push again. For the new functions, I think I should be able to devise a test in the 'tests/' folder Marco |
I also noticed an error message during the tests, stating "itertools has no 'izip' member". A possible workaround I found online could be to just use zip, but import itertools as in the following |
I think this approach is reasonable. We do something similar at https://github.com/HEPData/hepdata_lib/blob/master/hepdata_lib/__init__.py#L17-L21. However, we now have six as a requirement for the tests (see https://github.com/HEPData/hepdata_lib/blob/master/setup.py#L40-L41), and I think there's no harm actually making it a full dependency. You could then work around this issue by simply doing from six.moves import zip Your suggestion is equally valid though and I have no strong opinion. |
@cippy Thanks a lot for your efforts! I made a few changes to |
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 added a few comments and suggestions. Thank you for providing comments to document the new functions you implemented!
It would be nice if you added some smaller tests of the individual new functions you added. At the moment, you test round_value_and_uncertainty
, which make use of the other new helper functions, but not the helper functions themselves. If you don't have time for that, let me know, and we can merge this now and create an issue to add more tests at a later point.
tests/test_helpers.py
Outdated
for index in range(len(cont_asymm_err["val"])): | ||
self.assertTrue(cont_asymm_err["val"] == cont_asymm_err["val_round"]) | ||
self.assertTrue(cont_asymm_err["unc"] == cont_asymm_err["unc_round"]) |
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.
Should these lines actually use [index]
to check each individual item? I changed that with my last commit in lines 49-50, but wanted to ask what was your intention here.
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.
Your are right, initially I was thinking of making a check item by item, but eventually I forgot to add "[index]" after each set of square brackets. However, I think the direct comparison of the arrays is just equivalent and even simpler, the loop could be removed
Hi, sorry for the spam and the many commits to fix pylint errors. With the last commits I implemented all the comments received above. I also added a fix to relative_round(), where I moved the check for the tuple input type as the first one. The problem was that if type(value) == tuple and the check is first made for 'value == 0', a ValueError is thrown, because 'The truth value of an array with more than one element is ambiguous'. |
Thanks for your work! I checked and can confirm that the failing test for MacOS is not due to your code, but rather other things going wrong with the pyROOT installation there. |
@AndreasAlbert I'd merge this early next week unless you have additional comments. Let me know should you need more time. |
All changes in hepdata_lib/helpers.py
These functions are mostly utilities to facilitate rounding of values stored in dictionaries as returned, e.g., by RootFileReader::read_hist_1d()
The main one is roundValueAndUncertainty(), which allows to round values according to the significant digits of their respective uncertainties (rounded to a given input precision).