TheAlgorithms/Python · error · ValueError
The parameter bwt_string must not be empty.
Error message
The parameter bwt_string must not be empty.
What it means
Raised by reverse_bwt() in data_compression/burrows_wheeler.py when bwt_string is a str but empty. The inverse BWT needs at least one character to reconstruct rotations, so empty input is rejected right after the type check.
Source
Thrown at data_compression/burrows_wheeler.py:142
of cast to int.
>>> reverse_bwt("mnpbnnaaaaaa", -1)
Traceback (most recent call last):
...
ValueError: The parameter idx_original_string must not be lower than 0.
>>> reverse_bwt("mnpbnnaaaaaa", 12) # doctest: +NORMALIZE_WHITESPACE
Traceback (most recent call last):
...
ValueError: The parameter idx_original_string must be lower than
len(bwt_string).
>>> reverse_bwt("mnpbnnaaaaaa", 11.0)
'panamabanana'
>>> reverse_bwt("mnpbnnaaaaaa", 11.4)
'panamabanana'
"""
if not isinstance(bwt_string, str):
raise TypeError("The parameter bwt_string type must be str.")
if not bwt_string:
raise ValueError("The parameter bwt_string must not be empty.")
try:
idx_original_string = int(idx_original_string)
except ValueError:
raise TypeError(
"The parameter idx_original_string type must be int or passive"
" of cast to int."
)
if idx_original_string < 0:
raise ValueError("The parameter idx_original_string must not be lower than 0.")
if idx_original_string >= len(bwt_string):
raise ValueError(
"The parameter idx_original_string must be lower than len(bwt_string)."
)
ordered_rotations = [""] * len(bwt_string)
for _ in range(len(bwt_string)):
for i in range(len(bwt_string)):
ordered_rotations[i] = bwt_string[i] + ordered_rotations[i]View on GitHub (pinned to f5988cc097)
Solutions
- Check the payload is non-empty before inverting: if bwt_str: reverse_bwt(bwt_str, idx).
- Investigate why the BWT string is empty — usually upstream data loss or truncation, since bwt_transform() never returns an empty bwt_string for valid input.
- Treat empty input as a data-integrity error in your pipeline rather than silently skipping.
Example fix
# before
plain = reverse_bwt(bwt_str, idx) # bwt_str == ''
# after
if not bwt_str:
raise ValueError('corrupt payload: empty BWT string')
plain = reverse_bwt(bwt_str, idx) Defensive patterns
Strategy: validation
Validate before calling
if not bwt_string:
raise ValueError('corrupt payload: empty BWT string')
plain = reverse_bwt(bwt_string, idx) Try / catch
try:
plain = reverse_bwt(bwt_string, idx)
except ValueError:
plain = '' # treat as empty original Prevention
- Verify payload integrity (length/checksum) before decoding
- An empty BWT string always means upstream data loss
When it happens
Trigger: Calling reverse_bwt('', 0), or passing an empty string after slicing/trimming a payload, e.g. reverse_bwt(data.split('\x00')[0], idx) when the split yields ''.
Common situations: Decoding a corrupted or truncated compressed payload, handling an empty file/stream chunk, or a pipeline bug that passes an empty placeholder instead of the real BWT output.
Related errors
- The parameter s must not be empty.
- The parameter idx_original_string must not be lower than 0.
- We need some text to work with.
- The parameter s type must be str.
- The parameter bwt_string type must be str.
AI-assisted analysis of TheAlgorithms/Python@f5988cc097 (2026-08-14).
Data as JSON: /api/errors/f9106e4331489b34.
Report an issue: GitHub.