{
  "id": "python/numpy-dtype-object-no-cast",
  "signature": "TypeError: Cannot cast array data from dtype('O') to dtype('float64') according to the rule 'safe'",
  "signature_zh": "TypeError: 根据 'safe' 规则无法将数组数据从 dtype('O') 转换为 dtype('float64')",
  "regex": "TypeError:\\ Cannot\\ cast\\ array\\ data\\ from\\ dtype\\('O'\\)\\ to\\ dtype\\('float64'\\)\\ according\\ to\\ the\\ rule\\ 'safe'",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "An object-dtype array (often a pandas column with mixed types or None) is being passed to a NumPy/SciPy routine that requires a numeric dtype with safe casting.",
  "root_cause_type": "generic",
  "root_cause_zh": "object dtype 数组（通常是含混合类型或 None 的 pandas 列）被传给需要安全转换数值 dtype 的 NumPy/SciPy 函数。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Raises ValueError on non-numeric strings",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Keeps object dtype",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "arr = pd.to_numeric(pd.Series(arr), errors='coerce').to_numpy(dtype=np.float64)",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "Clean first: arr = np.array([x for x in arr if x is not None], dtype=np.float64)",
      "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-08-15",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}