[Bug]: [Python] WriteToJson silently rounds floats to 10 decimal places
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 62/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- json, pandas, python, yaml
調査の方向性
丸めは DataFrame の経路から生じています。sdks/python/apache_beam/io/textio.py の WriteToJson は kwargs を apache_beam.dataframe.io.to_json に渡し、そこから pandas の to_json が呼ばれます。pandas の to_json では double_precision の既定値が 10 です。まず issue にある YAML パイプラインで再現させ、次に textio.py が to_json の呼び出しをどのように組み立てているかを確認してください。浮動小数点数が丸め誤差なしで往復できること(double_precision の適切な既定値、または行単位出力のための json.dumps 経路)と、textio または dataframe io のテストに 0.1234567890123 を扱うテストがあることをもって完了とします。
索引モデルが issue の本文から書いたものです。
説明
What happened?
beam.io.WriteToJson (and Beam YAML WriteToJson) silently loses float precision: values are rounded to 10 decimal places.
| input | written |
|---|---|
0.1234567890123 |
0.123456789 |
3.3333333333333335 |
3.3333333333 |
12345678901.5 |
12345678901.5 |
There is no warning, so a JSON export doesn't round-trip and differs from the same data written with WriteToParquet, WriteToCsv or json.dumps.
Minimal reproducer (Beam YAML, Beam 2.75.0; WriteToJson on master @ 728ef1b4 has the same code path):
pipeline:
type: chain
transforms:
- type: Create
config:
elements:
- {id: 1, x: 0.1234567890123}
- {id: 2, x: 3.3333333333333335}
- type: WriteToJson
config:
path: /tmp/c5
python -m apache_beam.yaml.main --yaml_pipeline_file=c5.yaml writes:
{"id":1,"x":0.123456789}
{"id":2,"x":3.3333333333}
Cause
WriteToJson (sdks/python/apache_beam/io/textio.py) writes through the DataFrame API, apache_beam.dataframe.io.to_json -> pandas.DataFrame.to_json, and only forwards the caller's **kwargs. pandas' to_json defaults to double_precision=10, so every float is rounded to 10 decimal places.
Options:
- Default
double_precision=15(pandas' maximum) when the caller doesn't pass it. That fixes most cases but still isn't exact for 16-17 significant digits. - Write JSON lines with
json.dumpsfororient='records', lines=True(the YAML default), which round-trips floats exactly.
At minimum the docstring should mention the rounding and the double_precision kwarg. Happy to send a PR for whichever approach maintainers prefer.
Issue Priority
Priority: 2 (default / most bugs should be filed as P2)
Issue Components
- Component: Python SDK
- Component: Java SDK
- Component: Go SDK
- Component: Typescript SDK
- Component: IO connector
- Component: Beam YAML
- Component: Beam examples
- Component: Beam playground
- Component: Beam katas
- Component: Website
- Component: Infrastructure
- Component: Spark Runner
- Component: Flink Runner
- Component: Prism Runner
- Component: Twister2 Runner
- Component: Hazelcast Jet Runner
- Component: Google Cloud Dataflow Runner
- 主要言語
- Java
- スター
- 8.7k
- フォーク
- 4.8k
- 平均マージ
- 2日 12時間
- マージ済み PR(30日)
- 371
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
apache/beam のほかの issue
-
awaiting triage bug P3
難易度 1/5 1時間未満 初心者へのやさしさ 67/100
apache/beam#41197 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
apache/beam#39624 · リアクション 2 件 ·
メンテナーはふだん 1 日以内に返信
-
[Bug]: PubsubIO used in batch incorrect batch cutoff size対応中かも @1fanwang が 78 日前に担当しました。 オープンbug io P3 pinned pubsub
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
apache/beam#28011 · コメント 4 件 ·
メンテナーはふだん 1 日以内に返信
-
build P3 sub-task
難易度 1/5 1時間未満 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
bug gcp io java P3
難易度 1/5 1時間未満 初心者へのやさしさ 65/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
SasanLabs/VulnerableApp#912 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
desktop edt not responding
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
datafusion-contrib/StreamFusion#653 ·
メンテナーはふだん 1 日以内に返信
-
[Bug] Absolute row/column index 0 is ignored for images, hyperlinks and comments対応中かも @fanOfSunny が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信