{
  "id": "python/pytest-approx-nan",
  "signature": "AssertionError: assert nan == 1.0",
  "signature_zh": "断言错误：断言nan等于1.0",
  "regex": "AssertionError:\\ assert\\ nan\\ ==\\ 1\\.0",
  "domain": "python",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "使用pytest.approx比较时，实际值为NaN，导致比较失败。",
  "root_cause_type": "generic",
  "root_cause_zh": "pytest.approx比较时，实际值为NaN，导致失败。",
  "versions": [
    {
      "version": "3.6",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "pytest.approx不支持NaN，需单独处理。",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "可能掩盖计算错误。",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.85,
      "how": "import math\nif math.isnan(actual):\n    pytest.fail('Actual value is NaN')\nelse:\n    assert actual == pytest.approx(expected)",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "def assert_float_equal(actual, expected):\n    if math.isnan(actual) or math.isnan(expected):\n        assert math.isnan(actual) == math.isnan(expected)\n    else:\n        assert actual == pytest.approx(expected)",
      "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.81,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2025-11-05",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}