Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion periodictable/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def parse_uncertainty(s):
# e.g., 23.0035(12) but not 23(1) or 23.0(1.0) or 23(1.0)
if '.' not in unc and '.' in value:
zeros = len(value.split('.')[1]) - len(unc)
unc = "0." + ("0"*zeros) + unc
unc = "".join(["0.", "0" * zeros, unc])
Copy link
Collaborator

@pkienzle pkienzle Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On my machine the new version is slower. I also find it a little less readable.

value, unc = "3.1415913", "15"

%timeit zeros = len(value.split('.')[1]) - len(unc); full_unc = "0." + ("0"*zeros) + unc
132 ns ± 1.89 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)

%timeit zeros = len(value.split('.')[1]) - len(unc); full_unc = "".join(["0.", "0" * zeros, unc])
148 ns ± 0.603 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)

If you want to update the PR using f-strings that would be okay.

%timeit zeros = len(value.split('.')[1]) - len(unc); full_unc = f"0.{'0' * zeros}{unc}"
115 ns ± 0.0236 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)

At 15 ns improvement per parsed number, I don't expect this to change startup times significantly, but every little bit helps.

[edit: changed "submit a new PR" to "update the PR"]
[edit: revised timing impact statement]

return float(value), float(unc)

# Plain value with no uncertainty
Expand Down