TheAlgorithms/Python · warning · ValueError
Scores cannot be empty
Error message
Scores cannot be empty
What it means
A defensive tail raise at the end of casimir_force() in physics/casimir_effect.py (line 113). After the (force, area, distance).count(0) != 1 guard at the top, the if force==0 / elif area==0 / elif distance==0 chain is exhaustive for exactly-one-zero inputs, so this line is effectively unreachable: it exists so the function never implicitly returns None if the invariant is ever broken by future edits.
Source
Thrown at backtracking/minimax.py:58
65
>>> minimax(-1, 0, True, scores, height)
Traceback (most recent call last):
...
ValueError: Depth cannot be less than 0
>>> minimax(0, 0, True, [], 2)
Traceback (most recent call last):
...
ValueError: Scores cannot be empty
>>> scores = [3, 5, 2, 9, 12, 5, 23, 23]
>>> height = math.log(len(scores), 2)
>>> minimax(0, 0, True, scores, height)
12
"""
if depth < 0:
raise ValueError("Depth cannot be less than 0")
if len(scores) == 0:
raise ValueError("Scores cannot be empty")
# Base case: If the current depth equals the height of the tree,
# return the score of the current node.
if depth == height:
return scores[node_index]
# If it's the maximizer's turn, choose the maximum score
# between the two possible moves.
if is_max:
return max(
minimax(depth + 1, node_index * 2, False, scores, height),
minimax(depth + 1, node_index * 2 + 1, False, scores, height),
)
# If it's the minimizer's turn, choose the minimum score
# between the two possible moves.
return min(
minimax(depth + 1, node_index * 2, True, scores, height),View on GitHub (pinned to f5988cc097)
Solutions
- If you hit this, verify you are calling casimir_force with exactly one 0 — if that still fails, you are running modified library code.
- Diff your local casimir_effect.py against upstream to find the edit that broke the invariant.
- Restore the original file or fix the modified guard so count(0)==1 aligns with the branch chain.
Defensive patterns
Strategy: try-catch
Try / catch
try:
result = casimir_force(force=f, area=a, distance=d)
except ValueError as e:
# defensive tail raise: indicates modified library code
raise RuntimeError("casimir_effect.py invariant broken; diff against upstream") from e Prevention
- Pin the library version in requirements.
- Diff local physics/casimir_effect.py against upstream after any patch.
- Keep the count(0)==1 guard and the if/elif chain in sync when forking.
When it happens
Trigger: Not reachable through the public API as written. Would only fire if the top guard or the branch chain were modified (e.g. a refactor changes the count check but not the branches), or if a value compares != 0 but also != 0 in float terms (not possible for reals).
Common situations: You will essentially never see this at runtime; if you do, you are likely running a patched/forked version of casimir_effect.py where the validation chain was edited and became inconsistent.
Related errors
- Expected a_coeffs to have {self.order + 1} elements for {sel
- Expected b_coeffs to have {self.order + 1} elements for {sel
- k must not be negative
- n must not be negative
- Candidates list should not be empty
AI-assisted analysis of TheAlgorithms/Python@f5988cc097 (2026-08-14).
Data as JSON: /api/errors/04f526c893cbbcd2.
Report an issue: GitHub.