{
  "id": "python/numpy-float-to-int-nan",
  "signature": "ValueError: cannot convert float NaN to integer",
  "signature_zh": "ValueError：无法将浮点型 NaN 转换为整数",
  "regex": "ValueError:\\ cannot\\ convert\\ float\\ NaN\\ to\\ integer",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "Attempting to cast a float array containing NaN into an integer dtype, which has no representation for NaN.",
  "root_cause_type": "generic",
  "root_cause_zh": "试图将包含 NaN 的浮点数组转换为整数 dtype，而整数类型无法表示 NaN。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "astype(int) still raises on NaN before truncation",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Silently drops data, corrupts downstream results",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "arr = np.nan_to_num(arr, nan=0.0).astype(int)",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "pd.Series(arr).dropna().astype(int) or fillna(0).astype(int)",
      "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.88,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-03-11",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}