# Parquet浮点数列的值在往返过程中由于模式中的浮点舍入导致0.1 + 0.2 != 0.3

- **ID:** `data/parquet-float-precision-loss-rounding`
- **领域:** data
- **类别:** type_error
- **验证级别:** ai_generated
- **修复率:** 75%

## 根因

Parquet使用FLOAT（32位）或DOUBLE（64位）类型；写入浮点值时，二进制表示导致精度损失，重新读取时可能在聚合或比较中引入额外的舍入误差。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| PyArrow 12.0 | active | — | — |
| Spark 3.4 | active | — | — |
| Parquet 2.0 | active | — | — |

## 解决方案

1. ```
   对于高精度列使用DOUBLE而非FLOAT：pd.read_parquet('file.parquet', dtype_backend='pyarrow')并转换为float64。
   ```
2. ```
   在比较浮点值时应用容差：if abs(a - b) < 1e-9: 视为相等。
   ```

## 无效尝试

- **Using Decimal type in Parquet schema to store all floats** — Decimal type can reduce precision loss but introduces performance overhead and may not be supported by all readers. (60% 失败率)
- **Rounding values to a fixed number of decimal places before writing** — Rounding can mask the issue but does not eliminate floating-point errors; comparisons still fail for edge cases. (70% 失败率)
