[Bug]: [Python] WriteToJson silently rounds floats to 10 decimal places
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 62/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- json, pandas, python, yaml
- Ambito
- data-engineering
Direzione di ricerca
L'arrotondamento deriva dal percorso DataFrame: WriteToJson in sdks/python/apache_beam/io/textio.py inoltra i kwargs ad apache_beam.dataframe.io.to_json, che chiama to_json di pandas, il cui double_precision ha come valore predefinito 10. Inizia riproducendo il problema con la pipeline YAML della issue, poi controlla come textio.py costruisce la chiamata a to_json. È fatto quando i float fanno un round-trip senza perdita (un valore predefinito adeguato per double_precision o un percorso json.dumps per l'output a righe) e un test nei test di textio o di dataframe io copre 0.1234567890123.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- Java
- Stelle
- 8.7k
- Fork
- 4.8k
- Merge medio
- 2g 9h
- PR unite (30g)
- 368
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
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 apache/beam
-
Release notes links wrongApertaawaiting triage bug P3
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 67/100
apache/beam#41197 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
apache/beam#39624 · 2 reazioni ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug]: PubsubIO used in batch incorrect batch cutoff sizeForse già presa @1fanwang l’ha presa 78 giorni fa. Apertabug io P3 pinned pubsub
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
apache/beam#28011 · 4 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
build P3 sub-task
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
bug gcp io java P3
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 65/100
I maintainer di solito rispondono entro 1 giorno
Issue simili
-
Enhancing the Issue TemplateAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
SasanLabs/VulnerableApp#912 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
desktop edt not responding
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
datafusion-contrib/StreamFusion#653 ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug] Absolute row/column index 0 is ignored for images, hyperlinks and commentsForse già presa @fanOfSunny l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno