{
  "id": "python/assertionerror-dict-approx-ordering",
  "signature": "E   AssertionError: assert {'a': 1.0, 'b': 2.0000000001} == {'a': 1.0, 'b': 2.0}\nE     Omitting 1 identical items, use -vv to show\nE     Differing items:\nE     {'b': 2.0000000001 != 2.0}",
  "signature_zh": "E   AssertionError: assert {'a': 1.0, 'b': 2.0000000001} == {'a': 1.0, 'b': 2.0}\nE     省略 1 个相同项，使用 -vv 显示\nE     差异项：\nE     {'b': 2.0000000001 != 2.0}",
  "regex": "E\\ \\ \\ AssertionError:\\ assert\\ \\{'a':\\ 1\\.0,\\ 'b':\\ 2\\.0000000001\\}\\ ==\\ \\{'a':\\ 1\\.0,\\ 'b':\\ 2\\.0\\}\\\nE\\ \\ \\ \\ \\ Omitting\\ 1\\ identical\\ items,\\ use\\ \\-vv\\ to\\ show\\\nE\\ \\ \\ \\ \\ Differing\\ items:\\\nE\\ \\ \\ \\ \\ \\{'b':\\ 2\\.0000000001\\ !=\\ 2\\.0\\}",
  "domain": "python",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "Float comparison inside nested dict/list structures fails because pytest.approx does not recurse into containers by default when comparing with ==; you must use pytest.approx on the whole structure or per-value.",
  "root_cause_type": "generic",
  "root_cause_zh": "嵌套 dict/list 结构中的浮点比较失败，因为使用 == 比较时 pytest.approx 默认不会递归到容器内部；需要对整个结构或每个值使用 pytest.approx。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "7.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "8.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Rounding both sides may still differ if the underlying computation drifts beyond the rounding boundary; it hides but does not fix the comparison semantics.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "String formatting is locale- and precision-sensitive; dict ordering and repr differences cause flaky failures.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "from pytest import approx\nassert result == approx({'a': 1.0, 'b': 2.0}, rel=1e-6)\n# approx recurses into dicts and lists",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "def approx_dict(d, rel=1e-6):\n    return {k: approx(v, rel=rel) if isinstance(v, float) else v for k, v in d.items()}\nassert result == approx_dict({'a': 1.0, 'b': 2.0})",
      "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.86,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-04-19",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}