{"record":{"id":"bad53d61deaa8617","repo":"TheAlgorithms/Python","slug":"the-parameter-s-must-not-be-empty","errorCode":null,"errorMessage":"The parameter s must not be empty.","messagePattern":"The parameter s must not be empty\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"data_compression/burrows_wheeler.py","lineNumber":81,"sourceCode":"    >>> bwt_transform(\"^BANANA\")\n    {'bwt_string': 'BNN^AAA', 'idx_original_string': 6}\n    >>> bwt_transform(\"a_asa_da_casa\")\n    {'bwt_string': 'aaaadss_c__aa', 'idx_original_string': 3}\n    >>> bwt_transform(\"panamabanana\")\n    {'bwt_string': 'mnpbnnaaaaaa', 'idx_original_string': 11}\n    >>> bwt_transform(4)\n    Traceback (most recent call last):\n        ...\n    TypeError: The parameter s type must be str.\n    >>> bwt_transform('')\n    Traceback (most recent call last):\n        ...\n    ValueError: The parameter s must not be empty.\n    \"\"\"\n    if not isinstance(s, str):\n        raise TypeError(\"The parameter s type must be str.\")\n    if not s:\n        raise ValueError(\"The parameter s must not be empty.\")\n\n    rotations = all_rotations(s)\n    rotations.sort()  # sort the list of rotations in alphabetically order\n    # make a string composed of the last char of each rotation\n    response: BWTTransformDict = {\n        \"bwt_string\": \"\".join([word[-1] for word in rotations]),\n        \"idx_original_string\": rotations.index(s),\n    }\n    return response\n\n\ndef reverse_bwt(bwt_string: str, idx_original_string: int) -> str:\n    \"\"\"\n    :param bwt_string: The string returned from bwt algorithm execution\n    :param idx_original_string: A 0-based index of the string that was used to\n    generate bwt_string at ordered rotations list\n    :return: The string used to generate bwt_string when bwt was executed\n    :raises TypeError: If the bwt_string parameter type is not str","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/data_compression/burrows_wheeler.py#L63-L99","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\nout = bwt_transform(chunk)  # chunk may be ''\n\n# after\nout = bwt_transform(chunk) if chunk else None","handlingStrategy":"validation","validationCode":"if not s:\n    raise ValueError('nothing to compress')\nresult = bwt_transform(s)","typeGuard":null,"tryCatchPattern":"try:\n    result = bwt_transform(s)\nexcept ValueError as e:\n    if 'must not be empty' in str(e):\n        result = None  # nothing to compress\n    else:\n        raise","preventionTips":["Filter empty chunks in streaming pipelines","Treat empty input as a no-op before compressing"],"tags":["value-validation","burrows-wheeler","empty-input","compression"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}