TheAlgorithms/Python · error · ValueError
The parameter s must not be empty.
Error message
The parameter s must not be empty.
What it means
Raised by bwt_transform() in data_compression/burrows_wheeler.py when s is a str but is empty (''). The Burrows-Wheeler transform of an empty string is undefined (there are no rotations and no original index), so the function explicitly rejects empty input after the type check.
Source
Thrown at data_compression/burrows_wheeler.py:81
>>> bwt_transform("^BANANA")
{'bwt_string': 'BNN^AAA', 'idx_original_string': 6}
>>> bwt_transform("a_asa_da_casa")
{'bwt_string': 'aaaadss_c__aa', 'idx_original_string': 3}
>>> bwt_transform("panamabanana")
{'bwt_string': 'mnpbnnaaaaaa', 'idx_original_string': 11}
>>> bwt_transform(4)
Traceback (most recent call last):
...
TypeError: The parameter s type must be str.
>>> bwt_transform('')
Traceback (most recent call last):
...
ValueError: The parameter s must not be empty.
"""
if not isinstance(s, str):
raise TypeError("The parameter s type must be str.")
if not s:
raise ValueError("The parameter s must not be empty.")
rotations = all_rotations(s)
rotations.sort() # sort the list of rotations in alphabetically order
# make a string composed of the last char of each rotation
response: BWTTransformDict = {
"bwt_string": "".join([word[-1] for word in rotations]),
"idx_original_string": rotations.index(s),
}
return response
def reverse_bwt(bwt_string: str, idx_original_string: int) -> str:
"""
:param bwt_string: The string returned from bwt algorithm execution
:param idx_original_string: A 0-based index of the string that was used to
generate bwt_string at ordered rotations list
:return: The string used to generate bwt_string when bwt was executed
:raises TypeError: If the bwt_string parameter type is not strView on GitHub (pinned to f5988cc097)
Solutions
- Skip empty inputs at the call site: if s: result = bwt_transform(s).
- Validate upstream and surface a domain-specific message instead of letting the library raise.
- For streaming pipelines, filter out empty chunks before compression.
Example fix
# before out = bwt_transform(chunk) # chunk may be '' # after out = bwt_transform(chunk) if chunk else None
Defensive patterns
Strategy: validation
Validate before calling
if not s:
raise ValueError('nothing to compress')
result = bwt_transform(s) Try / catch
try:
result = bwt_transform(s)
except ValueError as e:
if 'must not be empty' in str(e):
result = None # nothing to compress
else:
raise Prevention
- Filter empty chunks in streaming pipelines
- Treat empty input as a no-op before compressing
When it happens
Trigger: Calling bwt_transform(''), or passing a variable that became empty after a strip()/split()/slice operation, e.g. bwt_transform(user_input.strip()) where user_input was only whitespace.
Common situations: Processing files or streams where a chunk resolves to an empty string (end-of-input handling, blank lines), or after sanitizing input that turns out to contain nothing meaningful.
Related errors
- The parameter bwt_string 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/bad53d61deaa8617.
Report an issue: GitHub.