{
  "id": "python/pytest-approx-float-comparison-error",
  "signature": "AssertionError: assert 0.1 + 0.2 == 0.3 (pytest.approx used incorrectly)",
  "signature_zh": "断言错误：assert 0.1 + 0.2 == 0.3（pytest.approx 使用不正确）",
  "regex": "AssertionError:\\ assert\\ 0\\.1\\ \\+\\ 0\\.2\\ ==\\ 0\\.3\\ \\(pytest\\.approx\\ used\\ incorrectly\\)",
  "domain": "python",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "Floating point arithmetic leads to precision issues; using '==' directly fails, and pytest.approx must be applied to both sides or used as a context.",
  "root_cause_type": "generic",
  "root_cause_zh": "浮点运算导致精度问题；直接使用 '==' 会失败，并且必须将 pytest.approx 应用于两侧或作为上下文使用。",
  "versions": [
    {
      "version": "3.9",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.10",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Using round() on both values to compare",
      "why_fails": "Rounding can still introduce errors if the rounding precision is not chosen carefully.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "Comparing with == after converting to Decimal",
      "why_fails": "Decimal conversion may not be accurate if the original values are floats.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use pytest.approx to compare floating point values within tolerance.",
      "success_rate": 0.95,
      "how": "assert 0.1 + 0.2 == pytest.approx(0.3)",
      "condition": "",
      "sources": []
    },
    {
      "action": "Specify relative tolerance using pytest.approx with rel parameter.",
      "success_rate": 0.9,
      "how": "assert result == pytest.approx(expected, rel=1e-9)",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.87,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-05-30",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}