Skip to content
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/str format #170

Merged
merged 5 commits into from
Apr 20, 2023
Merged

Feat/str format #170

merged 5 commits into from
Apr 20, 2023

Conversation

fjosw
Copy link
Owner

@fjosw fjosw commented Apr 20, 2023

This PR adds a __format__ method to the Obs class and extends the functionality of _format_uncertainty.
For example the following code

o0 = pe.pseudo_Obs(-0.3, 0.421, "test")
o1 = pe.pseudo_Obs(0.21, 0.1452879, "test")
for i, o in enumerate([o0, o1]):
    print(f"Obs{i} {o:+3}")

now outputs three significant digits and adds a + sign to non-negative observables:

Obs0 -0.300(421)
Obs1 +0.210(145)

@fjosw fjosw requested a review from s-kuberski April 20, 2023 10:49
@s-kuberski
Copy link
Collaborator

Hi! Thanks for implementing this, I think it is a nice feature. Did you think about adding some more features (fill with whitespaces, scientific notation, alignment.... as outlined, e.g., here https://python-reference.readthedocs.io/en/latest/docs/functions/format.html) to the routine? It could be helpful for creating text output if some of the features that are supported for floats could be used for obs, as well.

@fjosw
Copy link
Owner Author

fjosw commented Apr 20, 2023

Thanks for the feedback. I now implemented "+", "-" and " " as in the documentation. For now I will not look into scientific notation or alignment. If needed alignment could be achieved with nested f-strings, for example:

print(f"{f'{o1:+3}':<20}text")
+0.3480(123)        text

@fjosw fjosw merged commit be061fd into develop Apr 20, 2023
@fjosw fjosw deleted the feat/str_format branch April 20, 2023 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants