{
  "id": "python/pytest-parametrize-list-mutation",
  "signature": "ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()",
  "signature_zh": "值错误：具有多个元素的数组的真值不明确。请使用 a.any() 或 a.all()",
  "regex": "ValueError:\\ The\\ truth\\ value\\ of\\ an\\ array\\ with\\ more\\ than\\ one\\ element\\ is\\ ambiguous\\.\\ Use\\ a\\.any\\(\\)\\ or\\ a\\.all\\(\\)",
  "domain": "python",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "Passing a numpy array as a parameter to a parametrized test without converting it to a list, causing ambiguity in truth testing.",
  "root_cause_type": "generic",
  "root_cause_zh": "将 numpy 数组作为参数传递给参数化测试，而未将其转换为列表，导致真值测试不明确。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Pytest may still try to evaluate the array's truth value.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "This changes the data type and may break the test logic.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "@pytest.mark.parametrize('arr', [np.array([1,2]).tolist()])",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "def id_func(arr):\n    return f'arr_{len(arr)}'\n@pytest.mark.parametrize('arr', [np.array([1,2])], ids=id_func)",
      "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.82,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2025-04-01",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}