{"record":{"id":"37d0e84fb75a847b","repo":"jax-ml/jax","slug":"condlist-must-be-non-empty","errorCode":null,"errorMessage":"condlist must be non-empty","messagePattern":"condlist must be non-empty","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/lax_numpy.py","lineNumber":2866,"sourceCode":"    This is logically equivalent to the following nested ``where`` statement:\n\n    >>> default = 0\n    >>> jnp.where(condlist[0],\n    ...   choicelist[0],\n    ...   jnp.where(condlist[1],\n    ...     choicelist[1],\n    ...     jnp.where(condlist[2],\n    ...       choicelist[2],\n    ...       default)))\n    Array([ 10,   2, 300,   0], dtype=int32)\n\n    However, for efficiency it is implemented in terms of :func:`jax.lax.select_n`.\n  \"\"\"\n  if len(condlist) != len(choicelist):\n    msg = \"condlist must have length equal to choicelist ({} vs {})\"\n    raise ValueError(msg.format(len(condlist), len(choicelist)))\n  if len(condlist) == 0:\n    raise ValueError(\"condlist must be non-empty\")\n\n  util.check_arraylike(\"select\", *condlist, *choicelist, default)\n  condlist = [asarray(cond) for cond in condlist]\n  choicelist = [asarray(choice) for choice in choicelist]\n  default = asarray(default)\n\n  # Put the default at front with condition False because\n  # argmax returns zero for an array of False values.\n  choicelist = util.promote_dtypes(default, *choicelist)\n  conditions = stack(broadcast_arrays(False, *condlist))\n  idx = argmax(conditions.astype(bool), axis=0)\n  return lax.select_n(*broadcast_arrays(idx, *choicelist))\n\ndef is_replicated_or_unreduced(sharding: NamedSharding) -> bool:\n  if sharding.spec.partitions:\n    return False\n  if sharding.spec.reduced:\n    return False","sourceCodeStart":2848,"sourceCodeEnd":2884,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/lax_numpy.py#L2848-L2884","documentation":"jnp.select requires at least one condition/choice pair; empty condlist (and choicelist) is rejected because there would be nothing to select.","triggerScenarios":"Calling jnp.select([], []) — often when condlist was dynamically built from a filter that matched nothing.","commonSituations":"Data-driven branch lists where all cases are filtered out at runtime; empty category lists in preprocessing pipelines.","solutions":["Guard with a fallback before calling: if not conds: return default array","Ensure at least one condition exists, e.g. add a final True catch-all: jnp.select([True], [default])"],"exampleFix":"// before\nresult = jnp.select(conds, choices, default=0)  # conds == []\n// after\nresult = jnp.select(conds + [True], choices + [0], default=0) if conds else jnp.zeros_like(x)","handlingStrategy":"fallback","validationCode":"if not condlist:\n    result = jnp.full_like(x, default)\nelse:\n    result = jnp.select(condlist, choicelist, default=default)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Guard dynamically-built branch lists for emptiness","Add a True catch-all condition as the final branch"],"tags":["jax","select","empty-list"],"backgroundTag":"empty-argument-list","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}