`pretty-format-json` modifies floating point numbers that have too many digits of precision
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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 ☹️.
- Lingua principale
- Python
- Stelle
- 6.7k
- Fork
- 800
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di pre-commit/pre-commit-hooks
-
Immutable Releases Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 45/100
pre-commit/pre-commit-hooks#1218 · 4 commenti · 2 reazioni ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
pre-commit/pre-commit-hooks#1020 · 8 commenti · 1 reazione ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 48/100
pre-commit/pre-commit-hooks#749 · 1 reazione ·
-
enhancement good-first-issue
Difficoltà 3/5 1-2 giorni Idoneità per principianti 55/100
pre-commit/pre-commit-hooks#612 · 13 commenti ·
-
Ban unarmored GPG keys Aperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
pre-commit/pre-commit-hooks#339 · 18 commenti · 2 reazioni ·
Tutte le issue di pre-commit/pre-commit-hooks
Issue simili
-
documentation help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 90/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 90/100
simonw/sqlite-utils#872 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100