`pretty-format-json` modifies floating point numbers that have too many digits of precision
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 35/100
Piste de recherche
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.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
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 ☹️.
- Langage dominant
- Python
- Étoiles
- 6.7k
- Forks
- 800
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de pre-commit/pre-commit-hooks
-
Immutable Releases Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 45/100
pre-commit/pre-commit-hooks#1218 · 4 commentaires · 2 réactions ·
-
Difficulté 4/5 3-5 jours Accessibilité débutants 35/100
pre-commit/pre-commit-hooks#1020 · 8 commentaires · 1 réaction ·
-
Difficulté 3/5 1-2 jours Accessibilité débutants 48/100
pre-commit/pre-commit-hooks#749 · 1 réaction ·
-
enhancement good-first-issue
Difficulté 3/5 1-2 jours Accessibilité débutants 55/100
pre-commit/pre-commit-hooks#612 · 13 commentaires ·
-
Ban unarmored GPG keys Ouverte
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 25/100
pre-commit/pre-commit-hooks#339 · 18 commentaires · 2 réactions ·
Toutes les issues de pre-commit/pre-commit-hooks
Issues similaires
-
triage/confirmed
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
agentscope-ai/agentscope#2775 ·
-
comp/desktop P3 type/bug
Difficulté 1/5 Moins d'une heure Accessibilité débutants 92/100
NousResearch/hermes-agent#118866 ·
-
bug
Difficulté 1/5 Moins d'une heure Accessibilité débutants 90/100
apache/cloudstack#14222 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100