`pretty-format-json` modifies floating point numbers that have too many digits of precision
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start by reproducing the issue with the pretty-format-json hook and inspect the high-precision-numbers branch and linked diff for its existing test case. Done means the hook preserves the input value 4.4257052820783003 in formatted output without losing decimal digits, with the regression test passing.
Written by the indexing model from the issue text.
Description
pretty-format-json modifies floating point numbers that have too many digits of precision.
Background
I have to work with JSON files that may be generated by non-python programs. These files, for whatever reason, have numbers that have up to 16 digits after the decimal place.
(It's absurd, really. The people taking these measurements are somehow able to measure 0.1μHz on a 10GHz scale?? Yeah, they're saving values like 5.9257052820783001 GHz. Someone needs to teach them about significant figures... but that's beside the point. The point is I have to deal with this data 😒)
Steps to Reproduce
- Create the following json file:
{"foo": 4.4257052820783003} - Run pretty-format-json on it.
Expected Output:
{
"foo": 4.4257052820783003
}
Actual Output:
{
"foo": 4.4257052820783
}
The diff from expected is:
{
- "foo": 4.4257052820783003
+ "foo": 4.4257052820783
}
Version Info
- pre-commit: 2.19.0
- pre-commit-hooks: v4.2.0
- Python: 3.8.8
- OS: Debian 11
Discussion
This might be something that has to be fixed within the python builtin json package. A custom JSON encoder/decoder that wraps things using decimal.Decimal might work too.
I've created a test case for this. See my high-precision-numbers branch or the diff.
I'll see if I have time to actually fix this, but I don't expect to ☹️.
- Dominant language
- Python
- Stars
- 6.7k
- Forks
- 800
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from pre-commit/pre-commit-hooks
-
Immutable Releases Open
Difficulty 2/5 1-3 hours Newbie friendliness 45/100
pre-commit/pre-commit-hooks#1218 · 4 comments · 2 reactions ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
pre-commit/pre-commit-hooks#1020 · 8 comments · 1 reaction ·
-
Difficulty 3/5 1-2 days Newbie friendliness 48/100
pre-commit/pre-commit-hooks#749 · 1 reaction ·
-
enhancement good-first-issue
Difficulty 3/5 1-2 days Newbie friendliness 55/100
pre-commit/pre-commit-hooks#612 · 13 comments ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
pre-commit/pre-commit-hooks#339 · 18 comments · 2 reactions ·
All issues in pre-commit/pre-commit-hooks
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100