`pretty-format-json` modifies floating point numbers that have too many digits of precision
还没有人认领这个 Issue。
评估
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
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 ☹️.
- 主要语言
- Python
- 星标
- 6.7k
- 派生
- 800
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
pre-commit/pre-commit-hooks 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 45/100
pre-commit/pre-commit-hooks#1218 · 4 条评论 · 2 个 reaction ·
-
难度 4/5 3-5 天 新手友好度 35/100
pre-commit/pre-commit-hooks#1020 · 8 条评论 · 1 个 reaction ·
-
难度 3/5 1-2 天 新手友好度 48/100
pre-commit/pre-commit-hooks#749 · 1 个 reaction ·
-
enhancement good-first-issue
难度 3/5 1-2 天 新手友好度 55/100
pre-commit/pre-commit-hooks#612 · 13 条评论 ·
-
难度 5/5 一周以上 新手友好度 25/100
pre-commit/pre-commit-hooks#339 · 18 条评论 · 2 个 reaction ·
查看 pre-commit/pre-commit-hooks 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 82/100
-
难度 2/5 1-3 小时 新手友好度 88/100
use-agent-os/agent-os#3314 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
BasedHardware/omi#15662 · 1 条评论 ·
-
documentation help wanted
难度 2/5 1-3 小时 新手友好度 90/100
-
难度 2/5 1-3 小时 新手友好度 62/100
AiursoftWeb/AnduinOS-2#19 ·